The SMTP server requires a secure connection, or the client failed authentication. Server response: 5.5.1 Authentication required

I have a problem when I send mail through this code, then an error occurs: "The SMTP server requires a secure connection or the client does not authenticate. Server response: 5.5.1 Authentication is required."

and my code:

protected void ImageButton1_Click(object sender, ImageClickEventArgs e) { MailMessage mail = new MailMessage(); mail.To.Add(" info@msslindia.com "); mail.From = new MailAddress(" info@msslindia.com "); string body = "<table><tr><td>Company Name:</td><td>" + txt_cname.Text + "</td></tr><tr><td>Address With No.:</td><td>" + txt_addwithno.Text + "</td></tr><tr><td>Contact Person:</td><td>" + txt_conperson.Text + "</td></tr><tr><td>Email Id</td><td>" + txt_email.Text + "</td></tr><tr><td>Description</td><td>" + txt_description.Text + "</td></tr></table>"; mail.Body = body; mail.IsBodyHtml = true; SmtpClient smtp = new SmtpClient(); smtp.Host = "smtp.gmail.com"; smtp.Port = 25; smtp.UseDefaultCredentials = true; smtp.Credentials = new System.Net.NetworkCredential(" info@msslindia.com ", "xyz"); smtp.EnableSsl = true; smtp.Send(mail); txt_cname.Focus(); txt_cname.Text = ""; txt_addwithno.Text = ""; txt_conperson.Text = ""; txt_email.Text = ""; txt_description.Text = ""; } 
+6
source share
6 answers

Google may deny application access to your account
Here you can enable apps to access your google account with your credentials:

https://accounts.google.com/DisplayUnlockCaptcha

+15
source

I think you should set UseDefaultCredentials to false, because you are defining the credentials for the connection.

Set this property to true if this SmtpClient object should, if requested by the server, authenticate using the default credentials of the current user.

[...]

If the UseDefaultCredentials property is set to false , then the value set in the Credentials property will be used for credentials when connecting to the server

+4
source

Try port 587 (it worked for me) and also set UseDefaultCredentials to false. Install it and try sending mail

+2
source

I think you are using the wrong port.

you should use 465

http://support.google.com/mail/bin/answer.py?hl=en&answer=13287

amuses

+1
source

The port does not really matter, since System.Net.Mail does not support implicit SSL, in other words, it completely ignores the "Port" parameter.

0
source

I tried to install this through SQL Server 2012 Database Mail and received the same message.

I was not able to get it working using my main g-mail account, which uses double authentication even after using a password for a specific application. I ended up trying to complete my second account, which does not have dual authorization, and it worked immediately. Therefore, for those who cannot make it work using one of the above solutions, try it with a standard gmail email account.

0
source

All Articles