- March 7, 2016 at 1:23 pm #36187
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)March 7, 2016 at 1:29 pm #36189
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.March 7, 2016 at 1:48 pm #36198
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!!!.March 7, 2016 at 8:26 pm #36224
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.Exception | Format-List * -Force $error.Exception.InnerException | Format-List * -ForceMarch 8, 2016 at 8:19 am #36273
Thanks I got it. the SMTP server name was wrong.
The issue resolved.
You must be logged in to reply to this topic.