Search code examples
powershellpowershell-4.0powershell-ise

Why does "send-mailmessage" work in Powershell Console but not in PowerShell ISE?


I am trying to send an email from PowerShell ISE.

The script I use is as simple as they get:

Send-mailmessage -from "[email protected]" -to "[email protected]" -subject "test" -smtpserver "smtp_server" 

It fails with an error message:

Send-mailmessage : Unable to connect to remote server

There are many reasons this could happen, answered in a lot of questions here. What puzzles me is that if I copy and paste the exact same script into a Powershell console, it works fine, and I get the mail.

What could cause this difference of behavior between Powershell ISE and Powershell Console?

I have tried to use the console powershell -command "mycommand". It sends the mail.

I have tried using the x86 versions of both with the same results, it works with the console, not with the ISE.


Solution

  • Can you try to disable the antivirus and run the code in ISE again? It might be possible that antivirus is blocking the outbound email.

    refer this issue on MS Technet discussing similar issue.