我用下面所示的代碼,並在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>
請檢查上面的代碼,並給我一個解決方案。
你確定你的憑據是正確的? – Neel 2014-09-03 05:32:46
defaultCredentials =「false」。嘗試將其設置爲true – Partha 2014-09-03 05:35:09