See this question's first two answers(曾經嘗試都,都產生下面的錯誤):PowerShell中發送電子郵件
代碼(根據需要更改件):
$EmailFrom = "[email protected]"
$EmailTo = "[email protected]"
$Subject = "Notification from XYZ"
$Body = "this is a notification from XYZ Notifications.."
$SMTPServer = "smtp.gmail.com"
$SMTPClient = New-Object Net.Mail.SmtpClient($SmtpServer, 587)
$SMTPClient.EnableSsl = $true
$SMTPClient.Credentials = New-Object System.Net.NetworkCredential("username", "password");
$SMTPClient.Send($EmailFrom, $EmailTo, $Subject, $Body)
其他方式(根據需要更改件):
$credentials = new-object Management.Automation.PSCredential 「[email protected]」, (「password」 | ConvertTo-SecureString -AsPlainText -Force)
Send-MailMessage -From $From -To $To -Body $Body $Body -SmtpServer {$smtpServer URI} -Credential $credentials -Verbose -UseSsl
我得到這個錯誤:
The SMTP server requires a secure connection or the client was not authenticated. The server response was: 5.5.1 Authentication Required. Learn more at
在第一個腳本中,端口是明確指定的,而不是使用PS的內置函數(儘管過去我沒有遇到這個函數的問題)。
謝謝!
我認爲[這](http://stackoverflow.com/questions/20906077/gmail-error-the -smtp-server-requires-a-secure-connection-or-the-client-was-not)可能會有幫助。 –