Click here to Skip to main content
14,241,236 members
Rate this:
Please Sign up or sign in to vote.
See more:
Hi!

I am trying to send and Email using SMTP Server but it gives an error.

following the Code.

Private Sub cmdSendEmail_Click(sender As System.Object, e As System.EventArgs) Handles cmdSendEmail.Click
       Try
            Dim UserName As String = "mymailid@gmail.com"
            Dim mail As MailMessage = New MailMessage
           
            mail.From = New MailAddress(UserName)
            mail.To.Add(New MailAddress(EmailTo@gmail.com))
            mail.Subject = "My Subject"
            mail.Body = "Message Body"
            mail.IsBodyHtml = True
            Dim client As SmtpClient = New SmtpClient("smtp.gmail.com", 587)
            client.EnableSsl = True
            client.Credentials = New System.Net.NetworkCredential(UserName, "myemailpassword")
            client.Send(mail)
            MessageBox.Show("Email Sent", "Title", MessageBoxButtons.OK, MessageBoxIcon.Information)
        Catch ex As Exception
            MessageBox.Show(ex.Message)  
        End Try
End Sub


But it shows the following error

The SMTP server requires a secure connection or the client was not authenticated. The server response was: 5.5.1 Authentication Required. Learn more at


can anyone have any idea about it ??

Thanks !

Best Regards:
Asim Mughal
Posted
Comments
CHill60 31-Jan-16 18:06pm
   
I'm guessing you didn't supply the correct credentials

1 solution

Rate this:
Please Sign up or sign in to vote.

Solution 1

   

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)




CodeProject, 503-250 Ferrand Drive Toronto Ontario, M3C 3G8 Canada +1 416-849-8900 x 100