Click here to Skip to main content
15,899,754 members
Please Sign up or sign in to vote.
1.00/5 (1 vote)
See more:
Hi!

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

following the Code.

C#
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

C#
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

 
Share this answer
 

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



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900