2012-05-22 42 views
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 = ""; 

} 
+0

確定用戶名和密碼都正確嗎? (顯而易見的事情首先檢查!)嘗試通過他們的網站登錄到Gmail,使用完全相同的用戶名/密碼組合。 – Bridge

+0

@AndersLindahl完全重複 - 相同的OP。 – Bridge

+0

你不需要設置smtpClient.UseDefaultCredentials嗎? –

回答

10

你在哪裏託管您的網站? Gmail可防止無法識別的訪問您的帳戶。嘗試執行此代碼,然後轉至您的Gmail,它會詢問您的訪問嘗試是否來自您。允許應用程序,你就完成了。

相關問題