Question

im facing error when sending email. here is the error

Error Email Sending Failure

what is the actual error for this exception because i newbie in in this, by the way here is my code line:

 Try
                Dim SmtpServer As New SmtpClient()
                Dim mail As New MailMessage()

                SmtpServer.Credentials = New  _
                Net.NetworkCredential("test@gmail.com", "passwordexample")
                SmtpServer.EnableSsl = True
                SmtpServer.Port = 587
                SmtpServer.Host = "smtp.gmail.com"

                mail = New MailMessage()
                mail.From = New MailAddress("test@gmail.com")
                mail.To.Add("examplemail@gmail.com")
                mail.Subject = "Change Request Submitted"
                mail.Body = "Dear User, " & Environment.NewLine & Environment.NewLine & Environment.NewLine & Environment.NewLine & "One Notification have been submitted," & Environment.NewLine & "Please check the change request on the intranet application"

//ad this line the error SmtpServer.Send(mail)
                SmtpServer.EnableSsl = True
                MsgBox("Notification emailed successfully")
            Catch ex As Exception
                MsgBox(ex.ToString)
            End Try
Was it helpful?

Solution

Please see this answer...

Sending Email from Visual Basic

If you still can't send the email....

Have you enabled POP or IMAP in Gmail? Sign in to the Gmail web interface.Open the 'Forwarding and POP/IMAP' tab on your 'Settings' page, and configure IMAP or POP. After enabling this in Gmail, make sure you click 'Save Changes' so Gmail can communicate with your mail client.

If you have 2 step verification..

Get an Application-Specific Password Google will automatically generate a password that you will need only once, when you set up Google Mail on your mobile device or email software. You can easily generate a password for each device or email software you want to use.

Step 1: At the bottom of the 2-step verification screen, next to Application-specific passwords, click Manage application-specific passwords. The Authorized Access to your Google Account screen will open.

Step 2: On the Authorized Access to your Google Account screen, in the Name field, type in a name to help you remember what application you are using to access your account and click Generate password. You will then see a password which you will use to configure your mobile device or email software. Keep this screen open until you are ready to enter the password (see part 4, below). The password creation with the device name will show at the bottom. When you are done using the password, click Done.

Step 3: To set up a password for another device or email software, simply type in the name of it in the Name field and click Generate password. You will receive another password.

See more here...

http://www.oit.umass.edu/support/google-apps/configure-google-mail-email-software-mobile-devices

OTHER TIPS

  Dim SmtpServer As New SmtpClient()
    SmtpServer.Credentials = New Net.NetworkCredential("EMAIL FROM@gmail.com", "YOUR PASSWORD")
    SmtpServer.Port = 25
    SmtpServer.Host = "smtp.gmail.com"
    SmtpServer.EnableSsl = True
    Dim omail As New MailMessage()


    omail.From = New MailAddress("FROM EMAIL @gmail.com", "Message", System.Text.Encoding.UTF8)

    omail.Subject = "test subject"
    omail.To.Add("test@gmail.com")

    SmtpServer.SendAsync(omail, Nothing)

Catch ex As Exception
    MsgBox(ex.ToString)
End Try

if that didn't work try SmtpServer.Port = 587

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top