Reputation: 81
Hoping someone can help with this. We have an app installed on a dedicated server that is giving the above error message when trying to send email messages out (either through a test or through a workflow). After many hours of troubleshooting, we determined that the issue was with the server itself (maybe). I ran a PS script to test the email functionality via 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 = '[email protected]'
To = '[email protected]', '[email protected]'
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
The email never sends and I get the following error:
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
The application throws the same error but since I brought it down to the PS level, I'm confident that this isn't an app issue. I ran IISCrypto and enabled TLS 1.2 on both the client and server. I also tested the script on 2 other servers and my laptop and it sent the email every time. Im at a loss here on what could be causing this. This is on Server 2012 R2. The other servers that didnt have an issue were also Sever 2012 R2. The other strange thing is that the issue inside the application seems to be consistently inconsistent. It almost seems that there is another app that is stepping in and blocking access to TLS.
Upvotes: 1
Views: 4331
Reputation: 31
[Net.ServicePointManager]::SecurityProtocol = [Net.SecurityProtocolType]::Tls12
Worked for me
Upvotes: 3
Reputation: 73
Add this line and it should be working...
[Net.ServicePointManager]::SecurityProtocol = [Net.SecurityProtocolType]::Tls12
Upvotes: 1