[英]Smtp.Send throws no error when reciepent has incorrect email address
I am sending email using SmtpClient.Send Method , but when I try to send to a non-existent email account, the Send method throws no exception, how can I tell that the recipient mail address is valid, or the mail won't arrive, or detect this issue. 我正在使用SmtpClient.Send方法发送电子邮件,但是当我尝试发送到不存在的电子邮件帐户时,Send方法不会抛出异常,如何判断收件人邮件地址有效,否则邮件不会到达,或检测到此问题。
code: 码:
Properties.Settings appSettings = new Properties.Settings();
MailMessage message = new MailMessage();
message.From = new MailAddress(appSettings.senderMail);
message.Subject = appSettings.mailsubj;
message.Body = appSettings.mailbody;
Attachment attach = new Attachment(sOutput);
message.Attachments.Add(attach);
SmtpClient client = new SmtpClient(appSettings.SMTP);
client.SendCompleted += this.SendCompletedCallback;
foreach (String clientEmail in clientEmailList)
{
message.To.Clear();
message.To.Add(clientEmail);
//client.Send(message);
try
{
client.Send(message);
AddToLog(String.Format("\t{0}{1}", Properties.Resources.ResourceManager.GetString("MAIL_SEND_SUCCESS"), clientEmail));
}
catch (SmtpFailedRecipientException ex)
{
AddToLog(String.Format("\t{0}{1}:\n\t{2}", Properties.Resources.ResourceManager.GetString("MAIL_SEND_ERROR"), clientEmail, ex.Message));
}
catch (SmtpException smtp_Ex)
{
AddToLog(String.Format("\t{0}{1}:\t{2}", Properties.Resources.ResourceManager.GetString("MAIL_SEND_ERROR"), clientEmail, "Cannot connect to SMTP server."));
}
catch (Exception ex)
{
AddToLog(String.Format("\t{0}{1}:\n\t{2}", Properties.Resources.ResourceManager.GetString("MAIL_SEND_ERROR"), clientEmail, ex.Message));
}
// client.SendAsync(message, clientEmail);
}
When SMTP client sends a message, it doesn't know anything about validity of e-mail address, if this address belongs to the domain, that differs from SMTP server's domain. 当SMTP客户端发送消息时,它不知道有关电子邮件地址有效性的任何信息,如果该地址属于域,则不同于SMTP服务器的域。
This will be known only after your SMTP server will try to deliver a message to the recipient from another domain. 只有在您的SMTP服务器尝试将邮件从另一个域传递给收件人后,才能知道此信息。 Usually, in this case you'll receive a mail message with error.
通常,在这种情况下,您会收到一封错误的邮件。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.