Rebex Graph

.NET client library for MS Graph API (Exchange Online)

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

Back to feature list...

Advanced features

The sample code on this page assumes you have already connected and authenticated to Microsoft 365 (Exchange Online) server.

Impersonate another user 

Impersonation makes it possible to use one account to log into the Exchange server, but then act on behalf of a different user. To request impersonation, use GraphClient.Settings.Impersonation property:

// create Graph client instance, connect, log in
// ...

// impersonate the 'other' user
client.Settings.Impersonation = new GraphImpersonation("other@example.org");

// work with impersonated mailbox as usual
var otherMessages = client.GetMessageList(GraphFolderId.Inbox);

To switch back to the logged-on user, disable impersonation by setting GraphClient.Settings.Impersonation property to null:

// turn impersonation off
client.Settings.Impersonation = null;

Accessing shared mailboxes 

To perform operations on a shared mailbox (or another mailbox), impersonate the shared mailbox:

// create Graph client instance, connect
// ...

// login with user's OAuth access token
client.Login(token);

// impersonate a shared mailbox using its address
client.Settings.Impersonation = new GraphImpersonation("shared@example.org");

// work with shared mailbox as usual
var sharedMessages = client.GetMessageList(GraphFolderId.Inbox);

Advanced searching 

You can perform a fulltext search on a folder using GraphSearchQuery. Either pass the string to search for, or write a graph $search query:

// create Graph client instance, connect, log in
// ...

// find top page of messages including string 'Order' anywhere
var query = new GraphMessageSearchQuery()
{
    RawSearch = "Order"
};
var orders = client.Search(GraphFolderId.Inbox, query);

// print some info about found messages
foreach (GraphMessageInfo info in orders)
{
    Console.WriteLine("[{0}] {1}", info.ReceivedDate, info.Subject);
}

Back to feature list...