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
// ...

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

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

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

Advanced searching 

You can perform a fulltext search on a folder using GraphMessageSearchQuery. 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);

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

Throttling 

To improve resilience when facing rate limits or temporary service issues, the MaxThrottlingDelay and MaxThrottlingRetryCount settings can be adjusted to control how the client handles failed requests.

The MaxThrottlingDelay property specifies the maximum wait time for retries, while MaxThrottlingRetryCount limits the number of retry attempts. These options facilitate smooth communication with the server during brief outages or throttling events.

Back to feature list...