title: Secure Connection for SMTP
body: <p>I have this simple script that sends an email using SMTP. </p>
  
  <pre class="lang-bsh prettyprint-override"><code>$EmailFrom = "from@gmail.com"
  $EmailTo = "to@gmail.com"
  $Subject = "Reports"
  $Body = "Please see attachments"
  $SMTPServer = "smtp.gmail.com"
  $SMTPClient = New-Object Net.Mail.SMTPClient($SMTPServer, 587)
  $User = "from"
  $PWord = ConvertTo-SecureString –String "Password" –AsPlainText -Force
  $Credential = New-Object –TypeName "System.Management.Automation.PSCredential" –ArgumentList $User, $PWord
  Send-MailMessage -SmtpServer $SMTPServer -Credential $Credential -From $EmailFrom -To $EmailTo -Subject $Subject
  </code></pre>
  
  <p>I am facing an issue using <code>-UseSsl</code>. </p>
  
  <p>Using it, gives me the error</p>
  
  <blockquote>
    <p>Send-MailMessage : Server does not support secure connections.</p>
  </blockquote>
  
  <p>Not using it, gives me the error</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. 4sm4306203pav.33 - gsmtp</p>
  </blockquote>