title: System.Net.Mail.SmtpException The SMTP server requires a secure connection or the client was not authenticated
body: <p>I am trying to send SMTP email from my vb.net form application. When applying this code, I get the error below. What am I doing wrong?</p>
  
  <p><strong>Code:</strong></p>
  
  <pre><code>Imports System.Net.Mail
  
  Public Class Form1
  
      Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
          Try
              Dim SmtpServer As New SmtpClient()
              Dim mail As New MailMessage()
              SmtpServer.Credentials = New  _
              Net.NetworkCredential("myemail@gmail.com", "mypassword")
              SmtpServer.Port = 587
              SmtpServer.Host = "smtp.gmail.com"
              mail = New MailMessage()
              mail.From = New MailAddress("myemail@gmail.com")
              mail.To.Add("sendto@hotmail.co.uk")
              mail.Subject = "Test Mail"
              mail.Body = "This is for testing SMTP mail from GMAIL"
              SmtpServer.Send(mail)
              MsgBox("mail send")
          Catch ex As Exception
              MsgBox(ex.ToString)
          End Try
      End Sub
  End Class
  </code></pre>
  
  <p><strong>Error:</strong></p>
  
  <blockquote>
    <p>System.Net.Mail.SmtpException:  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><img src="https://i.stack.imgur.com/41SH5.png" alt="Error Message"></p>