2014-09-03 158 views
0

我用下面所示的代码,并在web.config文件中设置的设置,但我得到这个错误:发送邮件错误

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

代码:

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文件:

<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> 

请检查上面的代码,并给我一个解决方案。

+2

你确定你的凭据是正确的? – Neel 2014-09-03 05:32:46

+0

defaultCredentials =“false”。尝试将其设置为true – Partha 2014-09-03 05:35:09

回答

1

如这里记载: - 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:

  1. Please make sure you have set SMTP authentication correctly in your script, for sample code, please click here

  2. 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!"

0

SMTP服务器要求安全连接或客户端未通过身份验证。服务器响应是:5.5.1需要身份验证。了解更多

解决方案:
1.停用乌尔Gmail帐户第二检验code.then只有安全的邮件可以发送到client.otherwise验证码将阻止邮件发送活动。

2.defaultCredentials = “假”

3.Try这种简单的方法 Sending mail through C# And Asp.net