当我在调试模式下按下发送按钮到来自“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);
}
有人可能会说,这实际上是我尝试传送到的服务器返回的错误代码。(邮箱已满、邮箱地址无效等)
无论哪种方式,还是需要由邮件服务器的管理员解决?有谁可能知道为什么会发生此错误?
如果需要,愿意提供任何其他/更多信息。
提前致谢,