Rebex EWS

EWS, SMTP, MIME, S/MIME libraries for .NET

Download 30-day free trial Buy from $199
More .NET libraries

Back to feature list...

Easy-to-use API

A typical EWS (Exchange Web Services) session goes through the following steps:

Note: EWS protocol is only supported by Microsoft Exchange and Office 365.

Getting list of unread emails using Exchange Web Services (EWS) 

The following code finds all unread e-mail messages and prints information about each of them:

// create EWS client instance
using (var client = new Rebex.Net.Ews())
{
    // connect to Exchange server
    client.Connect(hostname, SslMode.Implicit);

    // authenticate
    client.Login(username, password);

    // to select folder to work with use either:
    // - client.FindFolder(EwsFolderId.Root, "folderName")
    // - predefined folder id
    var folder = EwsFolderId.Inbox;

    // get list of unread messages
    var list = client.Search(
        folder,
        EwsSearchParameter.IsRead(false));

    // print some info
    foreach (EwsMessageInfo messageInfo in list)
    {
        Console.WriteLine("From: {0}", messageInfo.From);
        Console.WriteLine("To: {0}", messageInfo.To);
        Console.WriteLine("Subject: {0}", messageInfo.Subject);
    }

    // disconnect (not required, but polite)
    client.Disconnect();
}
' create IMAP client instance
Using client = New Rebex.Net.Ews()
    ' connect to Exchange   server
    client.Connect(hostname, SslMode.Implicit)

    ' authenticate
    client.Login(username, password)

    ' to select folder to work with use either
    '  - client.FindFolder(EwsFolderId.Root, "folderName")
    '  - predefined folder id
    Dim folder = EwsFolderId.Inbox

    ' get list of unread messages
    Dim list As EwsMessageCollection = client.Search(
        folder,
        EwsSearchParameter.IsRead(False))

    ' print some info
    For Each messageInfo As EwsMessageInfo In list
        Console.WriteLine("From: {0}", messageInfo.From)
        Console.WriteLine("To: {0}", messageInfo.To)
        Console.WriteLine("Subject: {0}", messageInfo.Subject)
    Next

    ' disconnect (not required, but polite)
    client.Disconnect()
End Using

Back to feature list...