【问题标题】:Sending email error: Mailbox unavailable. Client host rejected发送电子邮件错误:邮箱不可用。客户端主机被拒绝
【发布时间】:2012-11-01 23:16:10
【问题描述】:

当我在调试模式下按下发送按钮到来自“txtMail”(接收方)的特定地址时,出现此“弹出”错误:

MailerException 未被用户代码处理
邮箱不可用。
服务器响应是:4.7.1 客户端主机被拒绝:找不到您的 主机名,[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);
            }

有些人可能会说这实际上是我尝试传送到的服务器返回的错误代码。 (邮箱已满、邮箱地址无效等)

无论哪种方式,还是需要由邮件服务器的管理员解决? 有没有人知道为什么会出现这个错误?

如果需要,愿意提供任何其他/更多信息。
提前致谢,

【问题讨论】:

  • SmtpClient 应该在 using 块中。

标签: c# asp.net class smtp smtpclient


【解决方案1】:

这看起来像是接收 SMTP 服务器拒绝了该邮件。我猜它试图对您的 IP 和主机名进行反向查找,但找不到匹配项。这是一种常见的反垃圾邮件做法。

【讨论】:

  • 我应该怎么做才能防止这种情况发生?
  • 使用不同的 smtp 服务器,或与系统管理员一起正确设置 smtp 服务器
  • //smtp.transip.nl
  • 有没有人可以帮助我?还是我真的需要正确设置一个新的 smtp 服务器
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2018-05-19
  • 2022-01-13
  • 1970-01-01
  • 1970-01-01
  • 2010-11-09
  • 2016-08-18
相关资源
最近更新 更多