title: What is wrong with this code that should send some email with google?
body: <pre><code>Shared Sub sendMail(ByVal title As String, ByVal content As String)
      Dim SmtpServer As New SmtpClient("smtp.gmail.com", 465)
      SmtpServer.EnableSsl = True
      SmtpServer.Credentials = New Net.NetworkCredential(username, password)
      Dim mail As New MailMessage(username, username, title, content)
      SmtpServer.Send(mail)
  End Sub
  </code></pre>
  
  <p>I got the result of</p>
  
  <pre><code>System.Net.Mail.SmtpException: 'Failure sending mail.'
  IOException: Unable to read data from the transport connection: net_io_connectionclosed.
  </code></pre>
  
  <p>What did I do wrong? Should I enable IMAP first at google?</p>
  
  <p>My code is based on <a href="https://stackoverflow.com/questions/18153542/how-do-i-send-a-gmail-email-in-vb-net">How do I send a gmail email in vb.net?</a></p>
  
  <p>If I use port 587 instead of 465 I got</p>
  
  <pre><code>System.Net.Mail.SmtpException: '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'
  </code></pre>
  
  <p>Using port 25 yield</p>
  
  <pre><code>SocketException: A connection attempt failed because the connected party did not properly respond after a period of time, or established connection failed because connected host has failed to respond 74.125.200.109:25
  </code></pre>
  
  <p>Using 465 yield the original error</p>