为什么 Send-MailMessage 无法通过端口 587 使用 STARTTLS 发送 [英] Why does Send-MailMessage fail to send using STARTTLS over Port 587

查看:28
本文介绍了为什么 Send-MailMessage 无法通过端口 587 使用 STARTTLS 发送的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

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

Why does sending an email message from PowerShell with the Send-MailMessage command using the flag -Port 587 produce an error.

命令:

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 命令

Send-Mailmessage : The SMTP server requires a secure connection or the client was not authenticated. The server response was: 5.7.0 Must issue a STARTTLS command first

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

The PowerShell documentation says adding -UseSSL should specify that a STARTTLS command be sent, but even adding this flag may not resolve your issues.

命令:

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

错误信息:

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

Send-Mailmessage : Unable to read data from the transport connection: An existing connection was forcibly closed by the remote host.

推荐答案

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

Some SMTP servers may have been hardened to only accept TLS 1.2 for negotiating STARTTLS. In many cases Windows is configured to send TLS 1.0 by default when -UseSSL is specified.

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

To force Send-MailMessage to use TLS 1.2 it is necessary to add a line to the script before executing the Send-MailMessage:

要么输入:

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

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

这篇关于为什么 Send-MailMessage 无法通过端口 587 使用 STARTTLS 发送的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
相关文章
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆