Click here to Skip to main content
15,885,278 members
Please Sign up or sign in to vote.
2.00/5 (1 vote)
See more:
System.Net.Mail.SmtpException: 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 at System.Net.Mail.MailCommand.CheckResponse(SmtpStatusCode statusCode, String response) at System.Net.Mail.MailCommand.Send(SmtpConnection conn, Byte[] command, String from) at System.Net.Mail.SmtpTransport.SendMail(MailAddress sender, MailAddressCollection recipients, String deliveryNotify, SmtpFailedRecipientException& exception) at System.Net.Mail.SmtpClient.Send(MailMessage message) at _Default.Button1_Click(Object sender, EventArgs e)

I am facing the same error when I try to send the mail on server.else when I compile and execute the same code on local machine then it's working fine. below are the code for sending message.
C#
Try
            Dim Smtp_Server As New SmtpClient
            Dim e_mail As New MailMessage()
            Smtp_Server.UseDefaultCredentials = False
            Smtp_Server.Credentials = New Net.NetworkCredential("gauravgupta1501@gmail.com", "*********")
            Smtp_Server.Port = 587
            Smtp_Server.EnableSsl = False
            Smtp_Server.Host = "smtp.gmail.com"

            e_mail = New MailMessage()
            e_mail.From = New MailAddress("gauravgupta1501@gmail.com")
            e_mail.To.Add("surjitiit@gmail.com")
            e_mail.Subject = "Query From" + txtname.Text
            e_mail.IsBodyHtml = False
            e_mail.Body = "Name :" + txtname.Text + ", EMail ID :" + txtEmail.Text + ", College Name :" + txtCollegename.Text + ", Mobile Number :" + txtMobile.Text + ", Query :" + txtComment.Text

            Smtp_Server.Send(e_mail)

            Label5.Visible = True
            txtCollegename.Text = ""
            txtComment.Text = ""
            txtEmail.Text = ""
            txtMobile.Text = ""
            txtname.Text = ""
        Catch error_t As Exception
            Label5.Visible = True
            Label5.Text = error_t.ToString

        End Try
Posted
Updated 2-Jul-14 2:54am
v2
Comments
[no name] 2-Jul-14 8:51am    
"mail on server" most likely the user account your code is running under does not have permission to use network resources.

1 solution

Error says it all...
Quote:
The SMTP server requires a secure connection or the client was not authenticated.
You should have EnableSsl = True instead of False, because Gmail works on SSL.

After doing this, the code should work. Otherwise make sure that credentials, which is used to connect to Gmail are correct.

For a full working code, see my past answer - sending email to gmail from asp.net[^].
 
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