Using Asp.Net to Process NDR Emails

If you’ve ever managed a mailing list or sent out an announcement to a distribution group then you have inevitably experienced non-delivery report (NDR) floods. These messages indicate delivery problems for your some of your recipients. In most cases the delivery issues are straight forward such as the mailbox no longer being valid. Investing time to track down an end user’s new email address is time consuming and unrealistic if you have thousands of addresses on your list. So the simple solution is to remove them. Again if you have a large list then removing them manually will be a considerable time investment so why not leverage some and automate it.


Process NDR messages with ListNanny

In a previous blog post I showed how you can remove spam messages using the components aspNetPOP3 and aspNetMime by It turns out they also have a fantastic component for processing NDR messages called ListNanny.  So in the example below I have quite a few delivery failures that need processing.



When using ListNanny the first step of your program should be importing the latest NDR definition file provided by AdvancedIntellect.

string defPath= "c:\\ndr.def.xml"; 
NDR.ImportDefinitionFile( defPath );

Next you’ll connect to the mailbox containing the NDR messages, iterate through them, identify the bounced email address and then delete the bounced message. In my example below I have have a separate function to remove the bounced address from my list but I won’t cover that.

    POP3 pop = new POP3(mailserver, userid, password);
    int messageCount = pop.MessageCount();
        for (int i = 0; i < messageCount; i++)
            string messageText = pop.GetMessageAsText(i);
            NDR ndrMessage = NDR.Parse(messageText);
            ndrEmail = ndrMessage.BouncedEmailAddress;



Depending on how you send out your announcements you may receive a non-delivery report that references multiple bounced email address. If that is the case you can use the example below to process the NDR and identify each individual recipient from the group that needs to be removed.

NDR ndrMessage = NDR.Parse(messageText);
ndrEmail = ndrMessage.BouncedEmailAddress;       
DSN dsn = ndrMessage.FindDSN();

         if (dsn != null)
             foreach (object recip in dsn.RecipientCollection)
                 DSNRecipient dr = (DSNRecipient)recip;
                 if (dr.FinalRecipient != null)
                    ndrEmail = dr.FinalRecipient.Value;

In Summary

Managing non-delivery report (NDR) emails can be a challenge when you need to prune stale emails from your mailinglist. Fortunately the folks at have a great component called ListNanny which can help automate processing your NDR messages and minimize future bounce emails. Thanks for reading!

Peter Viola

Creative, customer focused, results oriented, Senior Web Systems Engineer who enjoys providing the highest level of customer service supporting complex Windows hosting solutions. MCITP, MCSA, MCTS

More Posts - Website