List and manipulate messages on Exchange Server

GemBox.Email allows you to work with mail messages stored on the Exchange Server.

The following example shows how to list the first 10 messages, print the body of unread messages and mark them as read.

Screenshot of mail messages listed with GemBox.Email
Mail messages listed with GemBox.Email
using System;
using GemBox.Email;
using GemBox.Email.Exchange;

class Program
{
    static void Main()
    {
        // If using Professional version, put your serial key below.
        ComponentInfo.SetLicense("FREE-LIMITED-KEY");

        // Create a new Exchange client.
        var exchangeClient = new ExchangeClient("<HOST> (e.g. https://outlook.office365.com/EWS/Exchange.asmx)");
        exchangeClient.Authenticate("<USERNAME>", "<PASSWORD>");

        // List the first ten messages in the Inbox folder.
        var messageInfos = exchangeClient.ListMessages("Inbox", 0, 10);

        foreach (ExchangeMessageInfo messageInfo in messageInfos)
        {
            if (!messageInfo.IsRead)
            {
                // Get the full mail message.
                var mailMessage = exchangeClient.GetMessage(messageInfo.ExchangeMessageId);
                Console.WriteLine("From: " + string.Join(", ", mailMessage.From));
                Console.WriteLine(mailMessage.BodyHtml);
                Console.WriteLine();

                // Mark message as read.
                exchangeClient.MarkMessageAsRead(messageInfo.ExchangeMessageId);
            }
        }
    }
}
Imports System
Imports GemBox.Email
Imports GemBox.Email.Exchange

Module Program

    Sub Main()

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

        ' Create a new Exchange client.
        Dim exchangeClient = new ExchangeClient("<HOST> (e.g. https://outlook.office365.com/EWS/Exchange.asmx)")
        exchangeClient.Authenticate("<USERNAME>", "<PASSWORD>")

        ' List the first ten messages in the Inbox folder.
        Dim messageInfos = exchangeClient.ListMessages("Inbox", 0, 10)

        For Each messageInfo As ExchangeMessageInfo in messageInfos
            If Not messageInfo.IsRead Then
            
                ' Get the full mail message.
                Dim mailMessage = exchangeClient.GetMessage(messageInfo.ExchangeMessageId)
                Console.WriteLine("From: " + string.Join(", ", mailMessage.From))
                Console.WriteLine(mailMessage.BodyHtml)
                Console.WriteLine()

                ' Mark message as read.
                exchangeClient.MarkMessageAsRead(messageInfo.ExchangeMessageId)
            End If
        Next

    End Sub
End Module

You can use the ExchangeClient.ListMessages method to list messages in a folder and the ExchangeClient.GetMessage method to obtain more information about a given message.

You can manipulate existing messages by using one of the following methods:

Check next example or download examples from GitHub.