header1   header
header
header Register : : Login header
header
connector   connector
menuleft menuright
submenu   submenu
left
Sending E-Mails With Powershell
Last Post 28 Jul 2010 03:34 AM by James. 4 Replies.
Printer Friendly
  •  
  •  
  •  
  •  
  •  
Sort:
PrevPrev NextNext
You are not authorized to post a reply.
Author Messages Not Resolved
JamesUser is Offline
Basic Member
Basic Member
Posts:374
Avatar

--
23 Jul 2010 08:34 AM

    Hello,

    I have found the following code on the internet:

    $SmtpClient = new-object system.net.mail.smtpClient
    $SmtpServer = "serveraddresshere.com"
    $SmtpClient.host = $SmtpServer

    $From = "Testing E-Mail Send mail@mail.com"
    $To = mail@mail.com
    $Title = "Test Subject"
    $Body = "Body Text"
    $SmtpClient.Send($from,$to,$title,$Body) 

    However when I run it I get the error of:

    Exception calling "Send" with "4" argument(s): "Failure sending mail."
    At line:1 char:17
    + $SmtpClient.Send <<<< ($from,$to,$title,$Body)
        + CategoryInfo          : NotSpecified: (:) [], MethodInvocationException
        + FullyQualifiedErrorId : DotNetMethodException

    I have tried internet and external server names and I am not getting anywhere I have tried on a client machine and a server however still the same does anyone know whats going on?

    Many Thanks

    James

    0ptikGhostUser is Offline
    Basic Member
    Basic Member
    Posts:296
    Avatar

    --
    26 Jul 2010 01:21 PM

    $SmtpClient.Send($from,$to,$title,$Body) is throwing an exception: "Failure sending mail."

    You'll need to catch the exception and inspect it for more information. Perhaps it has an InnerException that might give you more information:

    try { $SmtpClient.Send($from,$to,$title,$Body) } catch [System.Exception] { $_.Exception | Get-Member # show the exception's members to see what is available $_.Excepttion.InnerException # display the exception's InnerException if it has one }

    You'll need to play around with the exception you get back to see if it has any useful information.

    JamesUser is Offline
    Basic Member
    Basic Member
    Posts:374
    Avatar

    --
    27 Jul 2010 06:15 AM
    Hello,

    Many Thanks for that I have working code now I found a diffrent method for doing it and it works from my machine however when I try it on the terminal server it gives the error of:

    Exception calling "Send" with "1" argument(s): "Failure sending mail."
    At line:1 char:11
    + $smtp.Send <<<< ($msg)
    + CategoryInfo : NotSpecified: (:) [], MethodInvocationException
    + FullyQualifiedErrorId : DotNetMethodException

    The code has not changed and the same code can be used on my machine but it gives the above error when on the server does anyone know what needs to be enabled or installed on the server for it to work?

    Many Thanks

    James
    0ptikGhostUser is Offline
    Basic Member
    Basic Member
    Posts:296
    Avatar

    --
    27 Jul 2010 10:58 AM
    Again, you'll need to do some debugging. If you are not changing $SmtpServer then I would look at that server to determine why it accepts emails from your machine but not from the terminal server. If $SmtpServer points to the localhost, then you should make sure you have a SMTP server installed, configured, and running.
    JamesUser is Offline
    Basic Member
    Basic Member
    Posts:374
    Avatar

    --
    28 Jul 2010 03:34 AM
    Hello,

    I found the issue! It was mcafee!

    How dare it so added an exception in and everythings fine :)

    Many Thanks

    James
    You are not authorized to post a reply.


    Active Forums 4.3
    right
    footer   footer
    footer Sponsored by Quest Software • SAPIEN Technologies • Compellent • Microsoft Windows Server 2008 R2 footer
    footer   footer