In this article I will explain how to resolve the error Failure sending email in ASP.Net.
Generally the Failure sending email error comes when debugged leads to 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 in ASP.Net Application.
Thus this article will cover the common solutions which can resolve the issue.
 
 
Error
The following error occurs when you try to send email using Gmail credentials in your ASP.Net application.
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
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.5.1 Authentication Required. Learn more at
 
 
Solutions
1. Incorrect Gmail Username and/or password
First you must check whether the Username and Password supplied are correct.
Though Gmail allows you to sign in with Username instead complete Email but when sending email through code you need to pass the complete Email address as Username.
 
2. SSL setting
Gmail uses secure channel for sending emails and you need to enable SSL security while sending emails through your application.
In .Net it can be enabled by setting EnableSsl setting of the SmtpClient to True. For more information please refer my article Send email using Gmail SMTP Mail Server in ASP.Net.
 
3. Less Secure Apps setting
If you are sure that your Username and Password are correct, but you still get errors then it means that Gmail has blocked your application.
And in such case you will receive an email similar to what is shown below.
GMAIL SMTP Error: Failure sending email
 
Note: If you have not received email then use the following link.
 
Once you visit the link you need to modify the Less Secure Apps setting and Turn On access to Less Secure Apps as shown below.
GMAIL SMTP Error: Failure sending email
 
4. Application Location
If the solutions #1, #2 and #3 are not working for you then it might be the issue with the location of the Application accessing the Gmail account.
Gmail makes sure that your account is not being accessed from some other Country or geographical location which is far from your routine location i.e. your city when you live and access Gmail daily.
Generally the servers are not present in the same country or city where we live in and hence when you host your website on such server and try to send email from your application you might receive error.
Thus to resolve it, you will need to open browser on the server and login into Gmail. This makes Gmail understand that the server and its IP Address belongs to you and it will allow you to send emails through your application.