title: Windows Powershell SMTP server requires a secure connection
body: <p>I get 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.5.1 Authentication Required. Learn more at<br>
    At C:\documents\yes.ps1:22 char:1<br>
    + Send-MailMessage @EmailSplat<br>
    + ~~~~~~~~~~~~~~~~~~~~~~~~~~~~<br>
        + CategoryInfo          : InvalidOperation:   (System.Net.Mail.SmtpClient:SmtpClient) [Send-MailMessage], SmtpExcept
       ion<br>
        + FullyQualifiedErrorId : SmtpException,Microsoft.PowerShell.Commands.SendMailMessage</p>
  </blockquote>
  
  <pre><code>$MyEmail = "****@gmail.com"
  $SMTP= "smtp.gmail.com"
  $To = "****@gmail.com"
  $Subject = "Attachments"
  $Body = "Here's the attachment"
  $Creds = (Get-Credential -Credential "$MyEmail")
  $env:localappdata
  
  Start-Sleep 2
  $Attachments = get-childitem "$env:******" | select-object -ExpandProperty FullName
  $EmailSplat = @{To = $to
                  From = $MyEmail
                  Attachments = $Attachments
                  Subject = $Subject
                  Body = $Body
                  SmtpServer = $SMTP
                  Credential = $Creds
                  UseSsl = $True
                  Port = 587
                  DeliveryNotificationOption = 'never'
                  }
  Send-MailMessage @EmailSplat
  </code></pre>