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

List Email Messages with IMAP

Like the POP protocol, IMAP also supports message listing. Since messages are stored in folders, one must be selected before a listing. The example shows how to list messages in the INBOX folder using the ImapClient class.

List Messages 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
    static void Main(string[] args)
        // If using Professional version, put your serial key below.

        using (ImapClient imap = new ImapClient("<ADDRESS> (e.g."))

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

            // To be able to list message, we need to select a folder first

            // Get info for all messages in INBOX
            IList<ImapMessageInfo> infoList = imap.ListMessages();

            Console.WriteLine("Listing messages for folder '{0}' ...", imap.SelectedFolder.Name);

            foreach (ImapMessageInfo info in infoList)
                Console.WriteLine("{0} - [{1}] - {2} Byte(s)", info.Number, info.Uid, info.Size);
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.

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


            imap.Authenticate("<USERNAME>", "<PASSWORD>")

            ' To be able to list message, we need to select a folder first

            ' Get info for all messages in INBOX
            Dim infoList As IList(Of ImapMessageInfo) = imap.ListMessages()

            Console.WriteLine("Listing messages for folder '{0}' ...", imap.SelectedFolder.Name)

            For Each info As ImapMessageInfo In infoList
                Console.WriteLine("{0} - [{1}] - {2} Byte(s)", info.Number, info.Uid, info.Size)

        End Using

    End Sub

End Module

Check next sample.