捕获未送达的电子邮件 [英] catching undelivered emails

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

问题描述

我想一次发送大量电子邮件.我正在使用以下代码,我想捕获所有未送达的电子邮件.但是我无法做到这一点,它没有进入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);
    }

推荐答案

听起来像是在编写用于邪恶的程序.如果由于邮箱名称无效而导致邮件发送失败,那么我认为您不会在代码中收到任何通知,最好的办法是将发回邮件发送到您的发件人地址.

在我看来,构建密件抄送列表比一遍又一遍发送相同的电子邮件更有效.
Sounds like you''re writing a program used for evil. If a mail send fails because of an invalid mailbox name, then I don''t believe you get any notification in code, the best you can hope for, is a bounce message to your from address.

It does seem to me that it would be more efficient to build a BCC list than sending the same email over and over.


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

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆