我有一個問題,當通過此代碼發送一封郵件時,發生錯誤「SMTP服務器需要安全連接或客戶端未通過身份驗證,服務器響應爲: 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 = 25;
smtp.UseDefaultCredentials = true;
smtp.Credentials = new System.Net.NetworkCredential("[email protected]", "xyz");
smtp.EnableSsl = true;
smtp.Send(mail);
txt_cname.Focus();
txt_cname.Text = "";
txt_addwithno.Text = "";
txt_conperson.Text = "";
txt_email.Text = "";
txt_description.Text = "";
}
問題解決了嗎?因爲我有同樣的問題,並試圖修復它.. –
你可能想試試這個:http://stackoverflow.com/a/11513412/676508 –