Email Headers with IMAP

Apart from retrieving full mail messages, GemBox.Email can also enable you to get only the message headers. The headers contain information related to the message content and metadata. For more details, check out our Headers example.

To obtain the message headers, you need to use one of the ImapClient.GetHeaders methods. The result is a HeaderCollection object, which contains a collection of Header objects.

The following example shows how you can receive mail message headers using ImapClient.

Message headers with IMAP client in C# and VB.NET
Screenshot of message headers from ImapClient
using System;
using GemBox.Email;
using GemBox.Email.Imap;
using GemBox.Email.Mime;

class Program
{
    static void Main()
    {
        // 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();
            imap.Authenticate("<USERNAME>", "<PASSWORD>");

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

            // Display message headers.
            foreach (Header header in headers)
                Console.WriteLine($"{header.Name}: {header.Body}");
        }
    }
}
Imports System
Imports GemBox.Email
Imports GemBox.Email.Imap
Imports GemBox.Email.Mime

Module Program

    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()
            imap.Authenticate("<USERNAME>", "<PASSWORD>")

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

            ' Display message headers.
            For Each header As Header In headers
                Console.WriteLine($"{header.Name}: {header.Body}")
            Next
        End Using
    End Sub
End Module

For more information about ImapClient, check out our IMAP Client Connection example.

Want more?

Next example GitHub

Check the next example or select an example from the menu. You can also download our examples from the GitHub.


Like it?

Download Buy

If you want to try the GemBox.Email yourself, you can download the free version. It delivers the same performance and set of features as the professional version, but with some operations limited. To remove the limitation, you need to purchase a license.