1

This is my code to send email using GMAIL and VB.NET:

        Try
            Dim SmtpServer As New SmtpClient()
            SmtpServer.Credentials = New Net.NetworkCredential("mygmailid@gmail.com", "mypassword")
            SmtpServer.Port = 587
            SmtpServer.Host = "smtp.gmail.com"
            SmtpServer.EnableSsl = True

            mail = New MailMessage()
            mail.From = New MailAddress("mygmailid@gmail.com", "Asked for help", System.Text.Encoding.UTF8)
            Mail.To.Add("sendtoemail@id")
            Mail.Subject = "A help query has been raised"
            mail.Body = frm_dashboard.user_data_fetch.Item(1, 0).Value.ToString + " " + ask_for_help.txt_message_ask_help.Text
            SmtpServer.Send(Mail)
            MessageBox.Show("Mail sent")
        Catch ex As Exception
            MsgBox(ex.ToString())
            MessageBox.Show("Oops something went wrong.")
        End Try

But this shows me this error:-

enter image description here

Django Anonymous
  • 2,987
  • 16
  • 58
  • 106
  • 1
    Try `SmtpServer.DeliveryMethod = SmtpDeliveryMethod.Network: SmtpServer.UseDefaultCredentials = false` before setting the Credentials? Adapted from the [standard answer](http://stackoverflow.com/a/32336/15639) on Gmail and .Net (in C#, but it's straightforward to translate to VB) – MarkJ Sep 28 '12 at 12:25

1 Answers1

1

This is the order I have it in, you might want to try this:

Dim SMTP As New SmtpClient("smtp.gmail.com")
SMTP.Credentials = New System.Net.NetworkCredential("gmailID", "password")
SMTP.EnableSsl = True
SMTP.Port = "587"
SMTP.Send(Mail)

Also note that I don't actually use the "@gmail.com" when passing in my credentials.

nick
  • 425
  • 2
  • 4
  • 10