希望有人能帮忙。我们有一个应用程序安装在专用服务器上,当试图发送电子邮件消息时(无论是通过测试还是通过工作流程)给出上述错误信息。经过几个小时的故障排除,我们确定问题出在服务器本身(可能)。我运行了一个PS脚本,通过TLS
测试电子邮件功能。# Get the credential
$credential = Get-Credential
## Define the Send-MailMessage parameters
$mailParams = @{
SmtpServer = 'smtp.office365.com'
Port = '587' # or '25' if not using TLS
UseSSL = $true ## or not if using non-TLS
Credential = $credential
From = 'user@mydomain.com'
To = 'user@mydomain.com', 'user@notmydomain.com'
Subject = "SMTP Client Submission - $(Get-Date -Format g)"
Body = 'This is a test email using SMTP Client Submission'
DeliveryNotificationOption = 'OnFailure', 'OnSuccess'
}
## Send the message
Send-MailMessage @mailParams
电子邮件从未发送,我得到以下错误:
Send-MailMessage : Authentication failed because the remote party has closed the transport stream.
At line:18 char:1
+ Send-MailMessage @mailParams
+ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~
+ CategoryInfo : InvalidOperation: (System.Net.Mail.SmtpClient:SmtpClient) [Send-MailMessage], SmtpException
+ FullyQualifiedErrorId : SmtpException,Microsoft.PowerShell.Commands.SendMailMessage
应用程序抛出相同的错误,但因为我把它降低到PS级别,我相信这不是一个应用程序的问题。我运行IISCrypto并在客户端和服务器上启用TLS 1.2。我还在其他2台服务器和我的笔记本电脑上测试了脚本,每次都发送电子邮件。我不知道是什么引起的。这是在服务器2012 R2上。其他没有问题的服务器也是Sever 2012 R2。另一件奇怪的事情是,应用程序内部的问题似乎始终不一致。似乎有另一个应用程序正在介入并阻止对TLS的访问。
添加这一行,它应该可以工作了…
[Net.ServicePointManager]::SecurityProtocol = [Net.SecurityProtocolType]::Tls12
[Net.ServicePointManager]::SecurityProtocol = [Net.SecurityProtocolType]::Tls12
为我工作