Reputation: 1
I used the code shown below, and set setting in web.config
file, but I get this error:
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
Code:
protected void btnSubmit_Click(object sender, EventArgs e)
{
System.Net.Mail.MailMessage mail = new System.Net.Mail.MailMessage();
mail.Subject = "Demo to Semnd Message";
mail.To.Add("[email protected]");// ("[email protected]");
mail.IsBodyHtml = true;
mail.Body = "<html> <body> <div style='margin:10px;padding:5px;border:1px solid #fff000;'>" + txtMessage.Text + " </div> </body></html>";
System.Net.Mail.SmtpClient smtp = new System.Net.Mail.SmtpClient();
//smtp.EnableSsl = true;
smtp.Send(mail);
}
web.config
file:
<mailSettings>
<smtp from="[email protected]" deliveryMethod="Network">
<network defaultCredentials="false" host="smtp.gmail.com" port="587" password="password" userName="[email protected]" enableSsl="true"/>
</smtp>
</mailSettings>
Please check above code and give me a solution.
Upvotes: 0
Views: 157
Reputation: 1750
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.Disable ur gmail account second verification code.then only a secure mail can send to the client.otherwise the verification code will block the mail sending activity.
2.defaultCredentials="false"
3.Try this simple method Sending mail through C# And Asp.net
Upvotes: 0
Reputation: 11721
As documented here :- http://www.mywindowshosting.com/support/KB/a1546/send-email-from-gmail-with-smtp-authentication-but.aspx
Send email from Gmail with SMTP authentication but got "5.5.1 Authentication Required" error
You may get error message mentioned below when you using your gmail account to send email message through your script
The SMTP server requires a secure connection or the client was not authenticated. The server response was: 5.5.1 Authentication Required.
Solution:
Please make sure you have set SMTP authentication correctly in your script, for sample code, please click here
If there is no problem with your SMTP script, but you still got the message message mentioned above, it should because Gmail blocked the authentication from our server as it detected that it is the first time you login to your Gmail account from another Country or Location. You will need to login to gmail security center to approve the authntication. Once you approved it , please wait a few minutes then sending email from script again. Here are the steps to approve the "Unusual activity alerts" from gmail security center.
a) go to gmail security center via this link blow or google search for "gmail secrity" and login with your gmail account https://accounts.google.com/ServiceLogin?elo=1
b) next to "security" / "Recent activity" , click to "view all events"
c) You will able to see "Unusual Activity" , it will show all unusual activity events, select related event and approval it via click " Yes, That was me!"
Upvotes: 1