2012-11-01 48 views
0

當我按在調試模式下發送鍵,從「txtMail」一個特定的地址我得到這個「彈出」錯誤(接收器):
發送電子郵件錯誤:郵箱不可用。客戶端主機拒絕

MailerException was unhandled by user code
Mailbox unavailable.
The server response was: 4.7.1 Client host rejected: cannot find your hostname, [IP]

的代碼實際上絆倒了最後一行,也就是:

catch(Exception ex) 
      { 
       throw new MailerException(ex.Message, ex); 
      } 


我不認爲有一個與代碼本身有問題,但這裏是整個代碼,這樣也許有人能夠發現問題:

public void SendMail() 
     { 
      System.Net.Mail.MailMessage message = new System.Net.Mail.MailMessage(); 

      // Mail from 
      if (!string.IsNullOrEmpty(this.mailFrom)) 
       message.From = new MailAddress(this.mailFrom); 
      else 
       message.From = from; 

      if (!IsValidEmailAddress(message.From.Address)) 
       throw new MailAddressException("From address " + message.From + " is not valid"); 

      //message.From = from; 
      // Add recipients 
      if (_RecipientNames.Count == 0) 
       throw new RecipientException("No recipients added"); 


      StringBuilder Recipients = new StringBuilder(); 
      for(int i = 0; i < _RecipientEmailAddresses.Count; i++) 
      { 
       if (_RecipientNames[i].ToString().Length > 0) 
        message.To.Add(new MailAddress((string)_RecipientEmailAddresses[i], (string)_RecipientNames[i])); 
       else 
        message.To.Add(new MailAddress((string)_RecipientEmailAddresses[i])); 
      } 

      foreach (MailAddress ma in this._Bcc) 
       message.Bcc.Add(ma); 

      if (this._ReplyToAddress != null) 
       message.ReplyTo = this._ReplyToAddress; 

      message.Subject  = _Subject; 
      message.IsBodyHtml = this.isHtmlMail; 
      message.BodyEncoding = this.BodyEncoding; 

      // Priority 
      message.Priority = this.priorityLevel; 

      // Load template file? 
      if (_TemplateFile.Length > 0) 
      { 
       message.Body = GetMailTemplateContents(); 
      } 
      else 
       message.Body = _MailBody; 

      // Attachments given? 
      if (this.attachments.Count > 0) 
      { 
       foreach (Attachment a in this.attachments) 
        message.Attachments.Add(a); 
      } 

      SmtpClient client = new SmtpClient(_SmtpServer); 
      try 
      { 
       client.Send(message); 
      } 
      catch(System.Web.HttpException ex) 
      { 
       throw new MailerException(ex.Message,ex); 
      } 
      catch(System.Runtime.InteropServices.COMException ex) 
      { 
       // Rethrow the exception 
       throw new MailerException(ex.Message, ex); 

      } 
      catch(Exception ex) 
      { 
       throw new MailerException(ex.Message, ex); 
      } 

有人可能會說這實際上是我嘗試傳遞到的服務器返回的錯誤代碼。 (郵箱已滿,無效的電子郵件地址等)

無論哪種方式,還是需要由郵件服務器的管理員解決? 有沒有人可能知道爲什麼會出現這個錯誤?

願意根據需要提供任何其他/更多信息。
在此先感謝,

+0

'SmtpClient'應該在'using'塊中。 –

回答

1

這看起來像接收SMTP服務器拒絕郵件。我猜測它試圖對您的IP和主機名進行反向查找,但無法找到匹配項。這是一種常見的反垃圾郵件做法。

+0

我該怎麼做,以防止這種情況發生? – Lobato

+0

使用不同的SMTP服務器,或與系統管理員工作,以建立一個SMTP服務器正常 – JoshBerke

+0

//smtp.transip.nl < - 郵箱不可 \t \t \t //本地主機< - 該進程無法訪問該文件。因爲它正在被另一個進程使用。 \t \t \t // 25 < - 進程無法訪問該文件。因爲它正在被另一個進程使用。 (通過2個程序?) \t \t \t // SmtpServer < - 發送郵件失敗。 – Lobato

相關問題