I'm trying to get my head round the System.Net.Mail class but I'm having trouble finding decent documentation.
First query - Say I have an email with a CC and a BCC email, do I need to catch SmtpFailedRecipientsException instead of SmtpFailedRecipientException (note the singlular Recipient) or is it intended for sending to multiple TO recipients?
Second query - when I iterate through the exceptions using the method below, will the inner exceptions relate to the email addresses that have failed, such as the BCC but not the TO or CC. If this is the case will the resend then go to all 3 again?
static void CheckExceptionAndResend(SmtpFailedRecipientsException ex, SmtpClient client, MailMessage message)
{
var status = ex.StatusCode;
for (int i = 0; i < ex.InnerExceptions.Length; i++)
{
if (status == SmtpStatusCode.MailboxBusy ||
status == SmtpStatusCode.MailboxUnavailable ||
status == SmtpStatusCode.TransactionFailed)
{
System.Threading.Thread.Sleep(3000);
client.Send(message);
}
else
{
// TODO: Log delivery failure
}
}
}
All advice appreciated. Thanks in advance.