title: Send-MailMessage : Authentication failed because the
body: <p>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</p>
  <pre><code># 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                    = &quot;SMTP Client Submission - $(Get-Date -Format g)&quot;
      Body                       = 'This is a test email using SMTP Client Submission'
      DeliveryNotificationOption = 'OnFailure', 'OnSuccess'
  }
  
  ## Send the message
  Send-MailMessage @mailParams
  </code></pre>
  <p>The email never sends and I get the following error:</p>
  <pre><code>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
  </code></pre>
  <p>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.</p>