【发布时间】:2015-12-24 03:18:24
【问题描述】:
See this question's first two answers(都试过了,都报下面的错误):
代码(更改了必要的部分):
$EmailFrom = "notifications@somedomain.com"
$EmailTo = "me@earth.com"
$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 “mailserver@yourcompany.com”, (“password” | ConvertTo-SecureString -AsPlainText -Force)
Send-MailMessage -From $From -To $To -Body $Body $Body -SmtpServer {$smtpServer URI} -Credential $credentials -Verbose -UseSsl
我收到此错误:
SMTP 服务器需要安全连接,或者客户端没有 认证。服务器响应为:5.5.1 需要身份验证。 了解更多信息,请访问
在第一个脚本中,明确指定了端口,而它没有使用 PS 的内置函数(虽然我过去没有遇到过这个函数的问题)。
谢谢!
【问题讨论】:
-
我认为this 可能会有所帮助。
标签: email powershell