本文介绍了捕获未送达的电子邮件的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想一次发送大量电子邮件.我正在使用以下代码,我想捕获所有未送达的电子邮件.但是我无法做到这一点,它没有进入catch块.我需要FailedRecipients列表.
请任何人帮助我捕获所有未送达的邮件.

I want to send bulk number of emails at a time. I am using the following code, I want to catch all the emails which are undelivered.But i couldnt do that, It is not entering into the catch block.I need FailedRecipients list.
Please could any one help me in catching all the undelivered mails.

foreach (string recipient in ListOfRecipients)
{
    try
    {
        // Try to send an e-mail to each recipient:
        mailServer.Send(mailSender, recipient, mailSubject, mailBody);
    }
    catch (SmtpFailedRecipientException ex)
    {
        // Sending failed. Let's determine *why* and see if we can do anything about it:
        switch (ex.StatusCode)
        {
            case SmtpStatusCode.MailboxBusy:
                // ... wait for a couple of seconds, then try again:
                System.Threading.Thread.Sleep(3000);
                mailServer.Send(mailSender, recipient, mailSubject, mailBody);
                break;
            default:
                // ... in any other case, just give up and mark the recipient as 'failed':
                ListOfFailedRecipients.Add(recipient, ex.Message);
                break;
        }
    }
    catch (Exception ex)
    {
        // Catch any other exception as a 'failed' delivery:
        ListOfFailedRecipients.Add(recipient, ex.Message);
    }

推荐答案


这篇关于捕获未送达的电子邮件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

07-23 17:48