Send-MailMessage:无法从传输连接读取数据:net_io_connectionclosed
Send-MailMessage : Unable to read data from the transport connection: net_io_connectionclosed
我使用以下 PowerShell 脚本使用 Azure SendGrid 帐户详细信息发送电子邮件。执行脚本时,出现错误 Send-MailMessage : Unable to read data from the transport connection: net_io_connectionclosed
PoweShell 脚本:
$Username ="xxxxx@azure.com"
$Password = ConvertTo-SecureString "xxxx" -AsPlainText -Force
$credential = New-Object System.Management.Automation.PSCredential $Username, $Password
$SMTPServer = "smtp.sendgrid.net"
$EmailFrom = "from@mail.com"
$EmailTo = "to@mail.com"
$Subject = "SendGrid test"
$Body = "SendGrid testing successful"
Send-MailMessage -smtpServer $SMTPServer -Credential $credential -Usessl -Port 587 -from $EmailFrom -to $EmailTo -subject $Subject -Body $Body
所以,谁能建议我如何解决这个问题。
看起来像是网络连接问题,您可以检查以下内容:
- 如果您可以访问服务器上的 SMTP 端口 (587)。您可以使用 Telnet 来测试 SMTP 通信。参考this.
- 如果您输入了正确的参数(如凭据)。
有关更多信息,建议 use API Keys provided by SendGrid to send emails 而不是通过脚本发送密码。
我通过将安全协议更改为 TLS 1.2 修复了这个错误(在 non-Azure 环境中):
[System.Net.ServicePointManager]::SecurityProtocol = [System.Net.SecurityProtocolType]::Tls12;
详情:
相关:SmtpException: Unable to read data from the transport connection: net_io_connectionclosed
我使用以下 PowerShell 脚本使用 Azure SendGrid 帐户详细信息发送电子邮件。执行脚本时,出现错误 Send-MailMessage : Unable to read data from the transport connection: net_io_connectionclosed
PoweShell 脚本:
$Username ="xxxxx@azure.com"
$Password = ConvertTo-SecureString "xxxx" -AsPlainText -Force
$credential = New-Object System.Management.Automation.PSCredential $Username, $Password
$SMTPServer = "smtp.sendgrid.net"
$EmailFrom = "from@mail.com"
$EmailTo = "to@mail.com"
$Subject = "SendGrid test"
$Body = "SendGrid testing successful"
Send-MailMessage -smtpServer $SMTPServer -Credential $credential -Usessl -Port 587 -from $EmailFrom -to $EmailTo -subject $Subject -Body $Body
所以,谁能建议我如何解决这个问题。
看起来像是网络连接问题,您可以检查以下内容:
- 如果您可以访问服务器上的 SMTP 端口 (587)。您可以使用 Telnet 来测试 SMTP 通信。参考this.
- 如果您输入了正确的参数(如凭据)。
有关更多信息,建议 use API Keys provided by SendGrid to send emails 而不是通过脚本发送密码。
我通过将安全协议更改为 TLS 1.2 修复了这个错误(在 non-Azure 环境中):
[System.Net.ServicePointManager]::SecurityProtocol = [System.Net.SecurityProtocolType]::Tls12;
详情:
相关:SmtpException: Unable to read data from the transport connection: net_io_connectionclosed