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.
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);
}