2014-05-08 32 views
1

我有一個代碼,我正在發送郵件。當我在本地主機郵件上發送郵件時,可以輕鬆發送郵件,但是當我將代碼上傳到服務器。我得到這個例外在服務器上獲取異常SMTP服務器需要安全連接或客戶端未通過認證

System.Net.Mail.SmtpException: 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 at 
System.Net.Mail.MailCommand.CheckResponse(SmtpStatusCode statusCode, 
String response) at System.Net.Mail.MailCommand.Send(SmtpConnection 
conn, Byte[] command, MailAddress from, Boolean allowUnicode) at 
System.Net.Mail.SmtpTransport.SendMail(MailAddress sender, 
MailAddressCollection recipients, String deliveryNotify, Boolean 
allowUnicode, SmtpFailedRecipientException& exception) at 
System.Net.Mail.SmtpClient.Send(MailMessage message) at 
Admin_test.Page_Load(Object sender, EventArgs e) in 
d:\hostingspaces\abd9009\ihmsgr.domainNames.net\wwwroot\info\test.aspx.cs:line 
29 

我的代碼完美運行我的本地機器上,而其他服務器,但在服務器上 不起作用上是這樣的:

protected void Page_Load(object sender, EventArgs e) 
    { 
     System.Net.Mail.MailMessage mail = new System.Net.Mail.MailMessage(); 
     mail.To.Add("[email protected]"); 
     mail.From = new MailAddress("[email protected]", "Email 
head", System.Text.Encoding.UTF8); 
     mail.Subject = "This mail is send from asp.net application"; 
     mail.SubjectEncoding = System.Text.Encoding.UTF8; 
     mail.Body = "This is Email Body Text"; 
     mail.BodyEncoding = System.Text.Encoding.UTF8; 
     mail.IsBodyHtml = true; 
     mail.Priority = MailPriority.High; 
     SmtpClient client = new SmtpClient(); 
     client.Credentials = new 
System.Net.NetworkCredential("[email protected]", "MyPassword"); 
     client.Port = 587; 
     client.Host = "smtp.gmail.com"; 
     client.EnableSsl = true; 
     try 
     { 
      client.Send(mail); 
      } 
     catch (Exception ex) 
     { 
      Response.Write(ex); 
} 
} 

我使用的服務器http://www.arvixe.com/上主機空間請幫助

+3

儘快刪除此內容,並且不會傳播您的GMAIL用戶名和密碼! – Haney

+0

修改親愛的虛擬用戶名和密碼 – user3563009

+0

您仍然可以在修訂歷史記錄FYI中看到您的密碼。此時可能最容易更改密碼。您應該學習如何使用wireshark和telnet實際調試smtp流量,因爲您可能會遇到其他問題。 –

回答

1

試試這個。

1)EnableSSL真或假

2)檢查憑據再次

3)有時某些SMTP服務器(主要爲公司)不允許外部訪問或havea獨立IP的外部訪問

4)檢查用戶名是否應該包含@ Host.com或沒有它

我希望其中一個適合你。

+0

無法檢查所有這些 – user3563009

0

給我一個鏡頭,我剛剛面臨這個問題,解決了我的可能是一個不同的場景。 我的客戶給了我全新的[email protected]他的憑據,然後我試圖使用他們作爲憑據,然後我得到這個錯誤,因爲他至少沒有登錄過一次。我登錄和繁榮,它的工作

可能是這些東西可以幫助你

  1. 嘗試登錄到您的帳戶,更改密碼並設置新密碼(強之一)
  2. 使用try mail.UseDefaultCredentials = false;
相關問題