我想通过SMTP使用PowerShell发送电子邮件。无法使用PowerShell通过SMTP服务器发送电子邮件
我已经存储了这些变量在config.ps1文件
$smtpServer = "10.0.52.10"
$emailFrom = "[email protected]"
$emailTo = "[email protected]"
$emailsubject = "Health Check"
$emailbody = "Hi"
这是我的脚本发送电子邮件:
##################################################
#Send email with results
##################################################
. .\config.ps1
foreach ($line in $bodystring)
{
$emailbody = $emailbody + $line + "`r`n"
}
Send-MailMessage -To "$emailTo" -From "$emailFrom" -smtpServer "$smtpserver" -subject "$emailsubject" -body "$emailbody"
我得到这个错误:
Send-MailMessage : Unable to connect to the remote server
At C:\Users\administrator.SDC\Desktop\email.ps1:12 char:1
+ Send-MailMessage -To "$emailTo" -From "$emailFrom" -smtpServer "$smtpserver" -su ...
+ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
+ CategoryInfo : InvalidOperation: (System.Net.Mail.SmtpClient:SmtpClient) [Send-MailMessage], SmtpExcept
ion
+ FullyQualifiedErrorId : SmtpException,Microsoft.PowerShell.Commands.SendMailMessage
我的m是什么istake?我应该包括其他的东西来使它工作吗?
嗨,你不需要登录名和密码吗? SMTP服务器是否可以从这台计算机上访问? – sodawillow
yaaa ....对不对?但是,如何以及在哪里提供登录名和密码?/ – prudhvi
请参阅[此问题](http://stackoverflow.com/questions/12460950/how-to-pass-credentials-to-the-send-mailmessage-command例如发送电子邮件)。 – sodawillow