MailBee.NET Objects 4.0

HeaderCollection.Items Method 

Returns the collection of headers having the given name.

public HeaderCollection Items(
   string name
);

Parameters

name
The name of the header.

Remarks

This method should be used if the mail message contains several headers with the same name and the developer wants to examine them all. In other cases, it's easier to use Item property.

Example

This sample loads the message from .EML file and displays "Received" headers of the message.

[C#]
// To use the code below, import MailBee namespaces at the top of your code.
using MailBee;
using MailBee.Mime;

// The actual code (put it into a method of your class)

// Load the message from file.
MailMessage msg = new MailMessage();
msg.LoadMessage(@"C:\Docs\TestMail.eml");

// Access the list of "Received" headers.
HeaderCollection receivedHeaders = msg.Headers.Items("Received");

if (receivedHeaders != null)
{
    // For each header...
    foreach (Header hdr in receivedHeaders)
    {
        // Show the name and the value of the header.
        Console.WriteLine(string.Format("{0}: {1}", hdr.Name, hdr.Value));
    }
}
[Visual Basic]
' To use the code below, import MailBee namespaces at the top of your code.
Imports MailBee
Imports MailBee.Mime

' The actual code (put it into a method of your class)

' Load the message from file.
Dim msg As New MailMessage
msg.LoadMessage("C:\Docs\TestMail.eml")

' Access the list of "Received" headers.
Dim receivedHeaders As HeaderCollection = msg.Headers.Items("Received")

If Not receivedHeaders Is Nothing Then
    ' For each header...
    For Each hdr As Header In receivedHeaders
        ' Show the name and the value of the header.
        Console.WriteLine(String.Format("{0}: {1}", hdr.Name, hdr.Value))
    Next
End If

See Also

HeaderCollection Class | MailBee.Mime Namespace | Item | Header