7
可能重複:
The SMTP server requires a secure connection or the client was not authenticated. The server response was: 5.5.1 Authentication RequiredSMTP服務器需要安全連接或客戶端未通過身份驗證。服務器響應是:5.5.1需要身份驗證。
我有一個問題時,即時通訊運行該代碼,然後錯誤發生的是「SMTP服務器要求安全連接或客戶端未通過身份驗證的。服務器響應爲:5.5.1需要驗證「
而且我的代碼是:
代碼
protected void ImageButton1_Click(object sender, ImageClickEventArgs e)
{
MailMessage mail = new MailMessage();
mail.To.Add("[email protected]");
mail.From = new MailAddress("[email protected]");
string body = "<table><tr><td>Company Name:</td><td>" + txt_cname.Text + "</td></tr><tr><td>Address With No.:</td><td>" + txt_addwithno.Text + "</td></tr><tr><td>Contact Person:</td><td>" + txt_conperson.Text + "</td></tr><tr><td>Email Id</td><td>" + txt_email.Text + "</td></tr><tr><td>Description</td><td>" + txt_description.Text + "</td></tr></table>";
mail.Body = body;
mail.IsBodyHtml = true;
SmtpClient smtp = new SmtpClient();
smtp.Host = "smtp.gmail.com";
smtp.Port = 587;
smtp.Credentials = new System.Net.NetworkCredential("[email protected]", "12345");
smtp.EnableSsl = true;
smtp.Send(mail);
txt_cname.Focus();
txt_cname.Text = "";
txt_addwithno.Text = "";
txt_conperson.Text = "";
txt_email.Text = "";
txt_description.Text = "";
}
確定用戶名和密碼都正確嗎? (顯而易見的事情首先檢查!)嘗試通過他們的網站登錄到Gmail,使用完全相同的用戶名/密碼組合。 – Bridge
@AndersLindahl完全重複 - 相同的OP。 – Bridge
你不需要設置smtpClient.UseDefaultCredentials嗎? –