【问题标题】:Why does Send-MailMessage fail to send using STARTTLS over Port 587为什么 Send-MailMessage 无法通过端口 587 使用 STARTTLS 发送
【发布时间】:2019-05-16 01:48:04
【问题描述】:

为什么使用标志 -Port 587 从 PowerShell 通过 Send-MailMessage 命令发送电子邮件会产生错误。

命令:

Send-Mailmessage -smtpServer mail.server.com -Port 587 -from "admin@domain.com" -to "user@domain.com" -subject "Test" -body "Test"

错误信息:

Send-Mailmessage : SMTP 服务器需要安全连接或客户端未通过身份验证。服务器响应为:5.7.0 必须先发出 STARTTLS 命令

PowerShell 文档说添加 -UseSSL 应指定发送 STARTTLS 命令,但即使添加此标志也可能无法解决您的问题。

命令:

Send-Mailmessage -smtpServer mail.server.com -Port 587 -UseSsl -from "admin@domain.com" -to "user@domain.com" -subject "Test" -body "Test"

错误信息:

Send-Mailmessage : 无法从传输连接读取数据:现有连接被远程主机强行关闭。

【问题讨论】:

    标签: powershell ssl smtp tls1.2


    【解决方案1】:

    某些 SMTP 服务器可能已被强化为仅接受 TLS 1.2 来协商 STARTTLS。在许多情况下,Windows 配置为在指定 -UseSSL 时默认发送 TLS 1.0。

    要强制 Send-MailMessage 使用 TLS 1.2,有必要在执行 Send-MailMessage 之前向脚本添加一行:

    要么输入:

    [Net.ServicePointManager]::SecurityProtocol = [Net.SecurityProtocolType]::Tls12
    

    [System.Net.ServicePointManager]::SecurityProtocol = 'TLS12'
    

    【讨论】:

      猜你喜欢
      • 2015-06-16
      • 1970-01-01
      • 2010-11-18
      • 1970-01-01
      • 1970-01-01
      • 2020-08-03
      • 1970-01-01
      • 2014-11-23
      相关资源
      最近更新 更多