title: How to Send mail from visual basic 2010 professional
body: <p>I want to send a mail using gmail id, my code is as here under, but an error occurred. How can I solve this?</p>
  <pre class="lang-vb prettyprint-override"><code>Imports System.Net
  Imports System.Net.Mail
  
  Public Class Form1
  
      Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
          MsgBox(&quot;This will send a mail...&quot;)
          Try
  
              Dim smtpserver As New SmtpClient()
              Dim mail As New MailMessage()
              smtpserver.Credentials = New Net.NetworkCredential(&quot;myname@gmail.com&quot;, &quot;password&quot;)
              smtpserver.Port = 465
              smtpserver.Host = &quot;smtp.gmail.com&quot;
              mail = New MailMessage()
              mail.From = New MailAddress(&quot;myname@gmail.com&quot;)
              mail.To.Add(&quot;to mail id&quot;)
              mail.Subject = &quot;Test by bharat&quot;
              mail.Body = &quot;hello ooooooooooooooooooooooo&quot;
              smtpserver.Send(mail)
              MsgBox(&quot;Mail Sent&quot;)
          Catch ex As Exception
              MsgBox(ex.ToString)
              Close()
          End Try
  
  
      End Sub
  End Class
  </code></pre>