Friday, June 14, 2013

Send-MailMessage : Unable to connect to remote server Line 1 character 17 error in PowerShell 2.0

After running below code 

Send-MailMessage -to "" -from "" -Subject " Test message" -Body " Test message" -SmtpServer ""

If you run into error given below

Send-MailMessage : Unable to connect to the remote server 
At line:1 char:17
+ Send-MailMessage <<<< -to -from "" -subject " Troubleshooting"  -Body   "Some Text or file attachement" -sntpserver "smtpserver" 
       + CategoryInfo : InvalidOperation: (System.Net.Mail.SmtpClient:SmtpClient) [Send-MailMessage], SmtpException 
       + FullyQualifiedErrorId : SmtpException,Microsoft.PowerShell.Commands.Send MailMessage

Try this solution

Solution: one of the possible problem is your anti-virus software blocking to connect SMTP server using PowerShell

In my case it is McAfee


Right click on McAfee icon 
Click on Virus Scan Console
Double click on Access Protection on VirusScan Console
On Access Protection tab
Go to Anti-Virus Standard Protection
On right hand side, double click on Prevent mass mailing worms from sending mail
On process to exclude tab, add PowerShell.exe at the end
Click ok 
Click apply on Access Protection
Click ok

That's it and try again to send mail using Send-MailMessage 

Post  your question or comment

No comments:

Post a Comment