Send-MailMessage Error

This topic contains 4 replies, has 3 voices, and was last updated by Profile photo of Vishal Joshi Vishal Joshi 6 months, 3 weeks ago.

Viewing 5 posts - 1 through 5 (of 5 total)
  • Author
    Posts
  • #36187
    Profile photo of Vishal Joshi
    Vishal Joshi
    Participant

    Hi,
    I am new in powershell, i was trying to send a mail through powershell scripting and i am able to send only for gmail, ymail etc but not for private sector companies mail where i work like comanies mail domain is [email protected].

    I have SMTP server for those mails but it thows an error again and again

    Exception calling "Send" with "4" argument(s): "Failure sending mail."
    At line:9 char:17
    + $SMTPClient.Send <<<< ($EmailFrom, $EmailTo, $Subject, $Body) + CategoryInfo : NotSpecified: (:) [], MethodInvocationException + FullyQualifiedErrorId : DotNetMethodExceptionI was tried lots of methods but it not works. the powershell worsion on my system(os: win 7) is 1.0 Also i tried to execute this script from server end(win server 2008 r2 and 2012)$EmailFrom = "[email protected]" $EmailTo = "[email protected]" $Subject = "Notification from XYZ" $Body = "this is a notification from XYZ Notifications.." $SMTPServer = "smtp.ge.com" $SMTPClient = New-Object Net.Mail.SmtpClient($SmtpServer, 587) $SMTPClient.EnableSsl = $true $SMTPClient.Credentials = New-Object System.Net.NetworkCredential("[email protected]", "************"); $SMTPClient.Send($EmailFrom, $EmailTo, $Subject, $Body)

    #36189
    Profile photo of Don Jones
    Don Jones
    Keymaster

    So, you didn't format your code for the forums, making it hard to read.

    It looks like you are trying to use SMTP server smtp.ge.com. It is most likely that the server doesn't want to allow you to authenticate from a remote, unknown location. Most private SMTP servers have very strict rules about who can log on to send, and from where, because what you're doing is exactly what illegal spammers do when they want to hijack a server and relay spam mail.

    You should talk to the administrator of the SMTP server to see what their requirements are.

    #36198
    Profile photo of Vishal Joshi
    Vishal Joshi
    Participant

    Thanks, for help Don.

    I have one QQ.
    I was trying automate some manual process on server. We have some logs that we need to monitor so sometimes we get some error and we miss them. So i was trying to make a script on powershell to trigger mail whenever we get an error in this logs.

    Can you please suggest is there any way to do this through task schedular or anything else.
    I tried with tasks schedular but the issue was it throws a mail whenever the script run it never check the script ran successfully or not.
    Please suggest what can i do here appreciate for help!!!.

    #36224
    Profile photo of Dave Wyatt
    Dave Wyatt
    Moderator

    There should hopefully be more information about _why_ the mail couldn't be sent in your error object. "Failure sending mail" is incredibly unhelpful. After you run the script, try these commands to see if we can get a bit more info:

    $error[0].Exception | Format-List * -Force
    $error[0].Exception.InnerException | Format-List * -Force
    
    #36273
    Profile photo of Vishal Joshi
    Vishal Joshi
    Participant

    Thanks I got it. the SMTP server name was wrong.
    The issue resolved.

Viewing 5 posts - 1 through 5 (of 5 total)

You must be logged in to reply to this topic.