2012-11-01 50 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

相关问题