I have written the following code to send an email from a VB.net windows Form. Here is my 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("[email protected]")
toMailAddress = New System.Net.Mail.MailAddress("[email protected]")
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("[email protected]", "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
Whenever i click on a button send, it should send email to the address specified. Bu this code is giving some error saying Unable to connect to remote machine....
Here is the screenshot of exception

Can anybody please help me to fix this issue. or Please suggest if you have any working sample.