Windows Powershell SMTP服务器需要安全连接

时间:2018-04-28 16:46:08

标签: windows powershell

我收到错误:

  

Send-MailMessage:SMTP服务器需要安全连接,或者客户端未经过身份验证。服务器响应为:5.5.1需要身份验证。了解更多信息   在C:\ documents \ yes.ps1:22 char:1
  + Send-MailMessage @EmailSplat
  + ~~~~~~~~~~~~~~~~~~~~~~~~~~~~       + CategoryInfo:InvalidOperation:(System.Net.Mail.SmtpClient:SmtpClient)[Send-MailMessage],SmtpExcept      离子
      + FullyQualifiedErrorId:SmtpException,Microsoft.PowerShell.Commands.SendMailMessage

$MyEmail = "****@gmail.com"
$SMTP= "smtp.gmail.com"
$To = "****@gmail.com"
$Subject = "Attachments"
$Body = "Here's the attachment"
$Creds = (Get-Credential -Credential "$MyEmail")
$env:localappdata

Start-Sleep 2
$Attachments = get-childitem "$env:******" | select-object -ExpandProperty FullName
$EmailSplat = @{To = $to
                From = $MyEmail
                Attachments = $Attachments
                Subject = $Subject
                Body = $Body
                SmtpServer = $SMTP
                Credential = $Creds
                UseSsl = $True
                Port = 587
                DeliveryNotificationOption = 'never'
                }
Send-MailMessage @EmailSplat

2 个答案:

答案 0 :(得分:1)

没有此步骤的步骤是: 应用密码


允许安全性较低的应用之后,我仍然面临着同样的问题,因为Google最近更新了其身份验证机制。这是步骤

  1. 确保您尝试发送邮件的帐户已启用 双重身份验证 ,并且还 允许安全性较低的应用程序< / em>
  2. 如果第1步成功完成,您将可以看到 应用密码 选项。
  3. 只需在要使用Google帐户的地方选择适当的选项即可。

对于OP,“我的图像”显示所需的内容。

After Enabling Two Factor Authentication this is what should be there

After creating app password

答案 1 :(得分:0)

您需要在Google帐户中启用允许安全性较低的应用,因为Google可能阻止某些不使用现代安全标准的应用(或设备)尝试登录。

登录Google帐户,然后转到:

https://www.google.com/settings/security/lesssecureapps

启用允许安全性较低的应用选项。

Enable less secure apps option