List Email Messages with IMAP

The following example shows how you can get the list of messages from the INBOX folder via IMAP protocol and display their basic information using GemBox.Email in your C# and VB.NET applications.

using GemBox.Email;
using GemBox.Email.Imap;
using System;
using System.Collections.Generic;

class Program
{
    static void Main()
    {
        // If using the 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 GemBox.Email
Imports GemBox.Email.Imap
Imports System
Imports System.Collections.Generic

Module Program

    Sub Main()

        ' If using the 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
Listing messages with IMAP client in C# and VB.NET
Screenshot of messages listing from ImapClient

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 such as the flags, sequence number, size and unique designator.

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

See also


Next steps

GemBox.Email is a .NET component that enables you to read, write, receive, and send emails from your .NET applications using one simple API.

Download Buy