0

Here is the code I have to send the email:

Private Sub Button2_Click(sender As Object, e As EventArgs) Handles Button2.Click
        Try
            Dim SmtpServer As New SmtpClient
            SmtpServer.EnableSsl = True
            Dim mail As New MailMessage
            SmtpServer.Credentials = New Net.NetworkCredential("Frrizzeh@gmail.com", "Password here")
            SmtpServer.Port = "587"
            SmtpServer.Host = "smtp.gmail.com"
            mail = New MailMessage
            mail.From = New MailAddress("Frrizzeh@gmail.com")
            mail.To.Add("Frrizzeh@gmail.com")
            mail.Subject = TextBox1.Text
            mail.Body = TextBox2.Text
            SmtpServer.Send(mail)

        Catch ex As Exception
            MsgBox(ex.Message)

        End Try

However when I run the program it just returns this error:

The SMTP server requires a secure connection or the client was not authenticated.

The server server response was: 5.5.1 Authentication required.

Any ideas where I am going wrong?

Eric Leschinski
  • 146,994
  • 96
  • 417
  • 335
user3812866
  • 129
  • 1
  • 11
  • 1
    possible duplicate of [Getting an error when sending email through Gmail SMTP](http://stackoverflow.com/questions/20618368/getting-an-error-when-sending-email-through-gmail-smtp) – Ken White Jan 09 '15 at 18:16

3 Answers3

2

Try enabling less secure password from: https://www.google.com/settings/security/lesssecureapps so you can login from your app.

Also, try adding the following properties

SmtpServer.DeliveryMethod = SmtpDeliveryMethod.Network SmtpServer.UseDefaultCredentials = False

AP 2022
  • 738
  • 1
  • 5
  • 20
2

You might have two step verification enabled and if so you need to generate an app specific password for you to use. Ive answered this and provided code in another question like this before. See link below...

Fail Sending Email Unable To Connect the Remote Server

Community
  • 1
  • 1
Trevor
  • 7,777
  • 6
  • 31
  • 50
1

I had this problem and fixed it by changing my gmail password to a stronger one with upper, lower, symbol, numeric. It was funny that it worked fine from localhost but failed from my server.