MailBee.NET Objects 7.1

DsnRecipient.Items Property

Gets a StringDictionary collection of the DSN fields.

public System.Collections.Specialized.StringDictionary Items {get;}

Property Value

A StringDictionary object with all the fields in the DSN for the given recipient e-mail address.

Example

This code sample scans a folder of .EML files and shows their DSN data in different ways.

[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();

        // Process every message in the folder.
        foreach (string file in files)
        {
            msg.LoadMessage(file);
            Result result = parser.Process(msg);

            Console.WriteLine("\r\nProcessing of message with filename: " + file);

            if (result == null || result.DsnStructure == null)
            {
                Console.WriteLine("------------------------------------------------------");
                Console.WriteLine("This message doesn't have DSN MIME part.");
                Console.WriteLine("------------------------------------------------------");
            }
            else
            {
                Console.WriteLine("------------------ DSN part as text ------------------");
                Console.WriteLine(result.DsnStructure.ToString());
                Console.WriteLine("------------- DSN header as StringDictionary ---------");
                foreach (string key in result.DsnStructure.Items.Keys)
                {
                    Console.WriteLine("DSN item: {0} = {1}", key, result.DsnStructure.Items[key]);
                }
                Console.WriteLine("------------------------------------------------------");

                foreach (RecipientStatus res in result.Recipients)
                {
                    if (res.DsnInfo != null)
                    {
                        Console.WriteLine("DSN subpart for: {0} e-mail", res.EmailAddress);
                        Console.WriteLine("---------------- DSN subpart as text -----------------");
                        Console.WriteLine(res.DsnInfo.ToString());
                        Console.WriteLine("------------- DSN header as StringDictionary ---------");
                        foreach (string key in res.DsnInfo.Items.Keys)
                        {
                            Console.WriteLine("DSN subpart item: {0} = {1}", key, res.DsnInfo.Items[key]);
                        }
                        Console.WriteLine("------------------------------------------------------");
                    }
                }
            }
        }
    }
}
[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

        ' Process every message in the folder.
        For Each file As String In files
            msg.LoadMessage(file)
            Dim result As Result = parser.Process(msg)

            Console.WriteLine(ControlChars.CrLf & "Processing of message with filename: " & file)

            If result Is Nothing Or result.DsnStructure Is Nothing Then
                Console.WriteLine("------------------------------------------------------")
                Console.WriteLine("This message doesn't have DSN MIME part.")
                Console.WriteLine("------------------------------------------------------")
            Else
                Console.WriteLine("------------------ DSN part as text ------------------")
                Console.WriteLine(result.DsnStructure.ToString())
                Console.WriteLine("------------- DSN header as StringDictionary ---------")
                For Each key As String In result.DsnStructure.Items.Keys
                    Console.WriteLine("Dsn item: {0} = {1}", key, result.DsnStructure.Items(key))
                Next
                Console.WriteLine("------------------------------------------------------")

                For Each res As RecipientStatus In result.Recipients
                    If Not res.DsnInfo Is Nothing Then
                        Console.WriteLine("DSN subpart for: {0} e-mail", res.EmailAddress)
                        Console.WriteLine("---------------- DSN subpart as text -----------------")
                        Console.WriteLine(res.DsnInfo.ToString())
                        Console.WriteLine("------------- DSN header as StringDictionary ---------")
                        For Each key As String In res.DsnInfo.Items.Keys
                            Console.WriteLine("Dsn subpart item: {0} = {1}", key, res.DsnInfo.Items(key))
                        Next
                        Console.WriteLine("------------------------------------------------------")
                    End If
                Next
            End If
        Next
    End Sub
End Class

See Also

DsnRecipient Class | MailBee.BounceMail Namespace