Message Headers

Apart from receiving full mail messages, the ImapClient class can get only message headers by calling the GetHeaders method.

The example shows how to receive mail message headers using the GemBox.Email component.

Screenshot
Message Headers Screenshot

See the full code below.

using GemBox.Email;
using GemBox.Email.Imap;
using GemBox.Email.Mime;
using GemBox.Email.Security;
using System;
using System.Collections.Generic;
using System.Globalization;
using System.Net.Security;
using System.Security.Cryptography.X509Certificates;

class Sample
{
    [STAThread]
    static void Main(string[] args)
    {
        // If using Professional version, put your serial key below.
        ComponentInfo.SetLicense("FREE-LIMITED-KEY");

        using (ImapClient imap = new ImapClient("<ADDRESS> (e.g. imap.gmail.com)"))
        {
            imap.Connect();
            Console.WriteLine("Connected.");

            imap.Authenticate("<USERNAME>", "<PASSWORD>");
            Console.WriteLine("Authenticated.");

            // Get headers for first available mail message
            HeaderCollection headers = imap.GetHeaders(1);

            Console.WriteLine("Listing message headers...");

            foreach (Header header in headers)
                Console.WriteLine("{0}: {1}", header.Name, header.Body);
        }
    }
}
Imports System.Globalization
Imports System.Net.Security
Imports System.Security.Cryptography.X509Certificates
Imports GemBox.Email
Imports GemBox.Email.Imap
Imports GemBox.Email.Mime

Module Samples

    Sub Main()

        ' If using Professional version, put your serial key below.
        ComponentInfo.SetLicense("FREE-LIMITED-KEY")

        Using imap As New ImapClient("<ADDRESS> (e.g. imap.gmail.com)")

            imap.Connect()
            Console.WriteLine("Connected.")

            imap.Authenticate("<USERNAME>", "<PASSWORD>")
            Console.WriteLine("Authenticated.")

            ' Get headers for first available mail message
            Dim headers As HeaderCollection = imap.GetHeaders(1)

            Console.WriteLine("Listing message headers...")

            For Each header As Header In headers
                Console.WriteLine("{0}: {1}", header.Name, header.Body)
            Next

        End Using

    End Sub

End Module