发送电子邮件错误:邮箱不可用。客户主机拒绝

时间:2012-11-01 15:10:41

标签: c# asp.net class smtp smtpclient

当我将调试模式下的发送按钮按下'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);
            }

有人可能会说这实际上是我试图传递给服务器的错误代码。 (邮箱已满,电子邮件地址无效等)

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

如果需要,愿意提供任何其他/更多信息 在此先感谢,

1 个答案:

答案 0 :(得分:1)

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