我想通過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