title: Sending email from VB.net Windows Form
body: <p>I have written the following code to send an email from a VB.net windows Form. 
  Here is my code</p>
  
  <pre><code>Try
          Dim message As System.Net.Mail.MailMessage
          Dim smtp As New System.Net.Mail.SmtpClient("smtp.gmail.com")
          Dim fromMailAddress As System.Net.Mail.MailAddress
          Dim toMailAddress As System.Net.Mail.MailAddress
  
          fromMailAddress = New System.Net.Mail.MailAddress("fromEmailID@live.com")
          toMailAddress = New System.Net.Mail.MailAddress("toEMailID@gmail.com")
  
          message = New System.Net.Mail.MailMessage()
          message.From = toMailAddress
          message.To.Add(fromMailAddress)
          message.Subject = "TestFromVB"
          message.Body = "Test Message"
  
          smtp.EnableSsl = True
          smtp.UseDefaultCredentials = False 
          smtp.Credentials = New System.Net.NetworkCredential("emailid@gmail.com", "password")
          smtp.DeliveryMethod = Net.Mail.SmtpDeliveryMethod.Network
  
          smtp.Send(message)
  
          MessageBox.Show("sent...") 
  
      Catch ex As Exception
          MessageBox.Show("error" + ex.Message + "\n" + ex.InnerException.ToString())
      End Try
  </code></pre>
  
  <p>Whenever i click on a button <strong>send</strong>, it should send email to the address specified. Bu this code is giving some error saying <strong>Unable to connect to remote machine....</strong></p>
  
  <p>Here is the screenshot of exception 
  <img src="https://i.stack.imgur.com/flR1l.jpg" alt="enter image description here"></p>
  
  <p>Can anybody please help me to fix this issue. or Please suggest if you have any working sample. </p>