title: How to fix 'the SMTP server requires a secure connection or the client was not authenticated' error when the server response was 5.7.0?
body: <p>I did turn on my less secure app in Gmail, I think the problem is SSL.</p>
  
  <p><a href="https://i.stack.imgur.com/A9fkI.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/A9fkI.png" alt="My powershell screenshot"></a></p>
  
  <p><a href="https://i.stack.imgur.com/xgAb5.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/xgAb5.png" alt="My current problem after changing port and $smtp"></a></p>
  
  <pre><code>$time = get-date 
  $smtpServer = “smtp.gmail.com”
  $smtp.EnableSSL = $true
  $smtp.Credentials = New-Object System.Net.NetworkCredential(“user”, “password”)
  $smtp = new-object Net.Mail.SmtpClient($smtpServer,587) **587 to 465**
  $msg = new-object Net.Mail.MailMessage
  $msg.From = (“myemail@gmail.com”)
  $msg.To.Add(“myemail@gmail.com”)
  $body=”Your message Body”
  $msg.Subject = “Mail From Gmail ” + $time
  #your file location
  $files=Get-ChildItem “C:\Users\Public\Pictures\LINE”
  Foreach($file in $files)
  {
  Write-Host “Attaching File :- ” $file
  $attachment = New-Object System.Net.Mail.Attachment –ArgumentList 
  C:\Users\Public\Pictures\LINE\$file
  $msg.Attachments.Add($attachment)
  }
  $smtp.Send($msg)
  $attachment.Dispose()
  $msg.Dispose()
  </code></pre>