find and solve || findandsolve.com
Please wait.....

SMTP server requires a secure connection or the client was not authenticated. The server response was: 5.7.0 Authenticat

SMTP server requires a secure connection or the client was not authenticated. The server response was: 5.7.0 Authenticat

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

Description: An unhandled exception occurred during the execution of the current web request. Please review the stack trace for more information about the error and where it originated in the code.

Exception Details: System.Net.Mail.SmtpException: The SMTP server requires a secure connection or the client was not authenticated. The server response was: 5.7.0 Authentication Required. Learn more at

I want to send an email from my application and i have written following code for sending mail.

                  System.Net.Mail.MailMessage m = new System.Net.Mail.MailMessage(
                    new System.Net.Mail.MailAddress("[email protected]", "MyProjectName"),
                    new System.Net.Mail.MailAddress(user.Email));
                    m.Subject = "Email confirmation";
                    string code = UserManager.GenerateEmailConfirmationToken(user.Id);
                    // added HTML encoding
                    string codeHtmlVersion = HttpUtility.UrlEncode(code);
                    string callbackUrl = "http://localhost:18607/Account/ConfirmEmail?userId=" +
                    user.Id + "&code=" + codeHtmlVersion;
                    m.Body = "Hi " + user.UserName +
                                       " You have been Successfully Register in MyProjectName.<br>" +
                                       "Please click on <a href =\"" + callbackUrl + "\">mydomamin.com link</a> to Login";
                    m.IsBodyHtml = true;
                    System.Net.Mail.SmtpClient smtp = new System.Net.Mail.SmtpClient("smtp.gmail.com");
                    smtp.Credentials = new System.Net.NetworkCredential("mydomainname[email protected]", "myGamilPassword");
                    smtp.EnableSsl = true;                     smtp.Port = 587;
                    smtp.Timeout = 20000;
                    //smtp.ServerCertificateValidationCallback = () => true; //Solution for client certificate error
                    smtp.EnableSsl = true;
                    smtp.Send(m);

Answer


Option 1.

Google may block sign in attempts from some apps or devices that do not use modern security standards like as 

"Some apps and devices use less secure sign-in technology, which makes your account vulnerable. You can turn off access for these apps, which we recommend, or turn it on if you want to use them despite the risks. Google will automatically turn this setting OFF if it’s not being used"

Therefore, you have to enable Less Secure Sign-In (or Less secure app access) in your google account.

After sign into google account, go to:

https://www.google.com/settings/security/lesssecureapps

or

https://myaccount.google.com/lesssecureapps


Option 2.

1.Incorrect Gmail Username and/or password

First you must check whether the Username and Password supplied are correct.

2.SSL setting.

Gmail uses secure channel for sending emails and you need to enable SSL security while sending emails through your application.

3.Less Secure Apps setting

Less secure apps setting like as given above Option 1.

Selena  Kandakar

Selena Kandakar

I like working on projects with a team that cares about creating beautiful and usable interfaces.

Comments



Report Response