Provides a method for examining e-mail messages for delivery or non-delivery notifications.
For a list of all members of this type, see DeliveryStatusParser Members.
System.Object
MailBee.BounceMail.DeliveryStatusParser
Public static (Shared in Visual Basic) members of this type are safe for multithreaded operations. Instance members are not guaranteed to be thread-safe.
This is the main class in the namespace. It provides facilities for extracting DSN information from e-mails.
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 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 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 inBounceDatabasefolder 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.
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\all.xml file.
[C#] // 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(@"C:\Temp\BounceDatabase\all.xml", true); string[] files = Directory.GetFiles(@"C:\Temp\IncomingMail", "*.eml"); MailMessage msg = new MailMessage(); // Check if e-mails are DSNs. foreach (string file in files) { msg.LoadMessage(file); Result result = parser.Process(msg); Console.WriteLine("\r\nProcessed e-mail: " + file); if (result == null) { Console.WriteLine("------------------------------------------------------"); Console.WriteLine("This message doesn't have DSN message part."); Console.WriteLine("------------------------------------------------------"); } else { // 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); Console.WriteLine("----------------------------------------------------"); } // 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); } } } } }
[Visual Basic] ' To use the code below, import these namespaces at the top of your code. Imports System.IO Imports Microsoft.VisualBasic Imports MailBee.Mime Imports MailBee.BounceMail Class Sample Shared Sub Main(ByVal args() As String) ' Load the templates database from file(s). Dim parser As DeliveryStatusParser = New DeliveryStatusParser("C:\Temp\BounceDatabase\all.xml", True) Dim files() As String = Directory.GetFiles("C:\Temp\IncomingMail", "*.eml") Dim msg As MailMessage = New MailMessage ' Check if e-mails are DSNs. For Each file As String In files msg.LoadMessage(file) Dim result As Result = parser.Process(msg) Console.WriteLine(ControlChars.CrLf & "Processed e-mail: " & file) If result Is Nothing Then Console.WriteLine("------------------------------------------------------") Console.WriteLine("This message doesn't have DSN message part.") Console.WriteLine("------------------------------------------------------") Else ' Get header params from the original e-mail message (for which the DSN message was sent). If Not result.OriginalMessage Is Nothing Then Console.WriteLine("-------------- Original message headers ------------") Console.WriteLine(ControlChars.Tab & "To: " & ControlChars.Tab & result.OriginalMessage.To.AsString) Console.WriteLine(ControlChars.Tab & "From: " & ControlChars.Tab & result.OriginalMessage.From.AsString) Console.WriteLine(ControlChars.Tab & "Subject:" & ControlChars.Tab & result.OriginalMessage.Subject) Console.WriteLine("----------------------------------------------------") End If ' Get the details for each e-mail address listed in the DSN. For Each res As RecipientStatus In result.Recipients Console.WriteLine("E-mail address: " & ControlChars.Tab & res.EmailAddress) Console.Write("Status: " & ControlChars.Tab & "is ") If res.IsBounced Then Console.WriteLine("bounced") Else Console.WriteLine("delivered successfully") Console.WriteLine("Common reason: " & ControlChars.Tab & res.Common.ToString()) Console.WriteLine("Detailed reason:" & ControlChars.Tab & res.Detailed.ToString()) Console.WriteLine("Description: " & ControlChars.Tab & res.Description) Next End If Next End Sub End Class
Namespace: MailBee.BounceMail
Assembly: MailBee.NET (in MailBee.NET.dll)
DeliveryStatusParser Members | MailBee.BounceMail Namespace