DeliveryStatusParser Class
Provides a method for examining e-mail messages for delivery or non-delivery notifications.
Inheritance Hierarchy

Namespace: MailBee.BounceMail
Assembly: MailBee.NET (in MailBee.NET.dll) Version: 11.2.0 build 590 for .NET 4.5
public class DeliveryStatusParser

The DeliveryStatusParser type exposes the following members.

Public methodCode exampleDeliveryStatusParser(Byte)
Loads DSN XML templates database from XML data and creates DeliveryStatusParser object.
Public methodCode exampleDeliveryStatusParser(String, Boolean)
Loads DSN XML templates database from a set of XML files and creates DeliveryStatusParser object.
Public methodEquals
Determines whether the specified object is equal to the current object.
(Inherited from Object.)
Protected methodFinalize
Allows an object to try to free resources and perform other cleanup operations before it is reclaimed by garbage collection.
(Inherited from Object.)
Public methodGetHashCode
Serves as the default hash function.
(Inherited from Object.)
Public methodGetType
Gets the Type of the current instance.
(Inherited from Object.)
Protected methodMemberwiseClone
Creates a shallow copy of the current Object.
(Inherited from Object.)
Public methodCode exampleProcess
Examines the specified MailMessage for delivery status notification (DSN) and returns its details.
Public methodProcessWithTimeout
Examines the specified MailMessage for delivery status notification (DSN) and returns its details, limiting the amount of time to process each bounce format.
Public methodToString
Returns a string that represents the current object.
(Inherited from Object.)

This is the main class in the namespace. It provides facilities for extracting DSN information from e-mails.

Note Note
This class is not supported in .NET Core and UWP apps yet.

The delivery status notification (DSN) is a reply from the recipient's mail software to the original message sender. This reply contains the mail delivery status of the original message: delivered successfully or bounced (failed, temporary undelivered, virus found or message treated as SPAM, etc).

Typical usage of this class if for mass mailing: you can easily detect e-mail addresses which could not receive e-mails and remove such addresses from your database to prevent further sending to these addresses. You can also track delivery (or non-deivery) of important e-mails.

To test whether the e-mail message is a delivery notification and examine its details, use Process(MailMessage) method.

If you send e-mails with Smtp component and then process bounces with DeliveryStatusParser, you can tune how destination mail servers should return bounces back to you by setting properties of DeliveryNotification object prior to sending an e-mail. For instance, you can set TrackingID for outgoing messages and then look for this ID in bounced messages using OriginalEnvelopeID property.

Note Note
There is no single standard of DSN messages. Instead, there are many hundreds of them, and new ones appear all the time. MailBee stores DSN formats as XML database where each entry is a template of a DSN message. By default, DSN templates database is installed in BounceDatabase folder of MailBee.NET Objects installation (for instance, C:\Program Files\MailBee.NET Objects\BounceDatabase). If you encounter a format which is not supported by the current database, contact us so that we would be able to update the database.

MailBee supports two formats of bounce database: folder tree of .XML files (where all.xml is root) and a single .xdb file. Single file is easier to use while "folder tree" version is easier to modify. .xdb version also supports loading from other storage, not just file. See DeliveryStatusParser(Byte) for details. "Folder tree" version, on other hand, supports loading multiple databases (e.g. standard and custom databases) at once. In most cases, .xdb is more convenient.


This sample tests all e-mails in the folder whether they are bounced messages and extracts all failed e-mail addresses contained in each bounced message.

It's assumed the e-mail samples are .EML files located in C:\Temp\IncomingMail folder. The DSN formats database resides in C:\Temp\BounceDatabase\bouncedatabase.xdb file.

This sample focuses on bounced messages. Autoreply messages is a special case, see notes in EmailAddress topic on how to extract email address for out-of-office replies.

// To use the code below, import these namespaces at the top of your code.
using System;
using System.IO;
using MailBee.Mime;
using MailBee.BounceMail;

class Sample
    static void Main(string[] args)
        // Load the templates database from file(s).
        DeliveryStatusParser parser = new DeliveryStatusParser(File.ReadAllBytes(@"C:\Temp\BounceDatabase\bouncedatabase.xdb"));

        string[] files = Directory.GetFiles(@"C:\Temp\IncomingMail", "*.eml");
        MailMessage msg = new MailMessage();

        // Check if e-mails are DSNs.
        foreach (string file in files)
            Result result = parser.Process(msg);

            Console.WriteLine("\r\nProcessed e-mail: " + file);

            if (result == null)
                Console.WriteLine("This message doesn't have DSN message part.");
                // Get header params from the original e-mail message (for which the DSN message was sent).
                if (result.OriginalMessage != null)
                    Console.WriteLine("-------------- Original message headers ------------");
                    Console.WriteLine("\tTo:     \t" + result.OriginalMessage.To.AsString);
                    Console.WriteLine("\tFrom:   \t" + result.OriginalMessage.From.AsString);
                    Console.WriteLine("\tSubject:\t" + result.OriginalMessage.Subject);

                // Get the details for each e-mail address listed in the DSN.
                foreach (RecipientStatus res in result.Recipients)
                    Console.WriteLine("E-mail address: \t" + res.EmailAddress);
                    Console.WriteLine("Status:         \tis " + (res.IsBounced ? "bounced" : "delivered successfully"));

                    Console.WriteLine("Common reason:  \t" + res.Common.ToString());
                    Console.WriteLine("Detailed reason:\t" + res.Detailed.ToString());
                    Console.WriteLine("Description:    \t" + res.Description);
See Also