how to mark emails as Read using latest Microsoft graph api C#

Athulya Pillai 46 Reputation points

Hello Team,

We used below code to mark emails as read using MS graph version 4.44

GraphServiceClient graphServiceClient =
                new GraphServiceClient(new DelegateAuthenticationProvider(async (requestMessage) =>
                    // Add the access token in the Authorization header of the API request.
                    requestMessage.Headers.Authorization =
                            new AuthenticationHeaderValue("Bearer", token);
            graphServiceClient.Users[ConfigElements.MSGraphUserName].Messages[id].Request().Select("IsRead").UpdateAsync(new Message { IsRead = true }).GetAwaiter().GetResult();

Now we update MS graph version to 5.0.4 and the above stopped working as DelegateAuthenticationProvider not found.

Please help me to mark the email as read using this updated version of MS Graph

Microsoft Graph
Microsoft Graph
A Microsoft programmability model that exposes REST APIs and client libraries to access data on Microsoft 365 services.
10,836 questions
0 comments No comments
{count} votes

1 answer

Sort by: Most helpful
  1. Siddharth Gautam 855 Reputation points

    Hello Athulya Pillai,

    Thanks for posting!

    As per my research, we can't use DelegateAuthenticationProvider any more to use it directly to new GraphServiceClient(delegateAuthenticationProvider), if we want to generate the auth_provider to new GraphServiceClient, we have to follow to use BaseBearerTokenAuthenticationProvider + IAccessTokenProvider. Please refer the below GitHub thread:

    Hope this helps.

    If the answer is helpful, please click Accept Answer and kindly upvote. If you have any further questions about this answer, please click Comment.