为什么 "send-mailmessage" 在 Powershell 控制台中有效,但在 PowerShell ISE 中无效?

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

我正在尝试从 PowerShell ISE 发送电子邮件。

我使用的脚本很简单:

Send-mailmessage -from "me@company.com" -to "me@company.com" -subject "test" -smtpserver "smtp_server" 

失败并显示错误消息:

Send-mailmessage : Unable to connect to remote server

发生这种情况的原因有很多,这里已经回答了很多问题。令我困惑的是,如果我将 完全相同的脚本 复制并粘贴到 Powershell 控制台中,它工作正常,并且我收到了邮件。

是什么导致了 Powershell ISE 和 Powershell 控制台之间的这种行为差异?

我试过使用控制台powershell -command "mycommand"。它发送邮件。

我试过使用两者的 x86 版本,结果相同,它适用于控制台,而不适用于 ISE。

您能否再次尝试禁用杀毒软件和 运行 ISE 中的代码?防病毒软件可能阻止了出站电子邮件。

refer this issue on MS Technet 正在讨论类似问题。