发送电子邮件错误:邮箱不可用。客户端主机拒绝
问题描述:
当我按在调试模式下发送键,从“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);
}
有人可能会说这实际上是我尝试传递到的服务器返回的错误代码。 (邮箱已满,无效的电子邮件地址等)
无论哪种方式,还是需要由邮件服务器的管理员解决? 有没有人可能知道为什么会出现这个错误?
愿意根据需要提供任何其他/更多信息。
在此先感谢,
'SmtpClient'应该在'using'块中。 –