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)可能会有帮助。 –