List Email Messages with IMAP

IMAP servers allow clients to list currently available messages in a specific folder. This can, for instance, enable you to use ImapClient to fetch the summary information of the emails and display the information to users without having to first download all of the messages from the server.

To obtain the message listing with GemBox.Email, you need to select the desired folder and then use one of the ImapClient.ListMessages methods. The returned collection of ImapMessageInfo objects contains only basic message information like the flags, sequence number, size and unique designator.

The following example shows how you can get the list of messages from the INBOX folder and display its information.

Listing messages with IMAP client in C# and VB.NET
Screenshot of messages listing from ImapClient
using System;
using System.Collections.Generic;
using GemBox.Email;
using GemBox.Email.Imap;

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>");

            // Select INBOX folder.
            imap.SelectInbox();

            // Get information about all available messages in INBOX folder.
            IList<ImapMessageInfo> infos = imap.ListMessages();

            // Display messages information.
            foreach (ImapMessageInfo info in infos)
                Console.WriteLine($"{info.Number} - [{info.Uid}] - {info.Size} Byte(s)");
        }
    }
}
Imports System
Imports System.Collections.Generic
Imports GemBox.Email
Imports GemBox.Email.Imap

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>")

            ' Select INBOX folder.
            imap.SelectInbox()

            ' Get information about all available messages in INBOX folder.
            Dim infos As IList(Of ImapMessageInfo) = imap.ListMessages()

            ' Display messages information.
            For Each info As ImapMessageInfo In infos
                Console.WriteLine($"{info.Number} - [{info.Uid}] - {info.Size} Byte(s)")
            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.