title: Why does Send-MailMessage fail to send using STARTTLS over Port 587
body: <p>Why does sending an email message from PowerShell with the Send-MailMessage command using the flag -Port 587 produce an error.  </p>
  
  <p>Command:</p>
  
  <pre><code>Send-Mailmessage -smtpServer mail.server.com -Port 587 -from "admin@domain.com" -to "user@domain.com" -subject "Test" -body "Test"
  </code></pre>
  
  <p>Error Message:</p>
  
  <blockquote>
    <p>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</p>
  </blockquote>
  
  <p>The PowerShell documentation says adding -UseSSL should specify that a STARTTLS command be sent, but even adding this flag may not resolve your issues.</p>
  
  <p>Command:</p>
  
  <pre><code>Send-Mailmessage -smtpServer mail.server.com -Port 587 -UseSsl -from "admin@domain.com" -to "user@domain.com" -subject "Test" -body "Test"
  </code></pre>
  
  <p>Eror message:</p>
  
  <blockquote>
    <p>Send-Mailmessage : Unable to read data from the transport connection: An existing connection was forcibly closed by the remote host.</p>
  </blockquote>