2014-09-03 428 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