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

Athulya Pillai 46 Reputation points
2023-03-31T11:33:45.3+00:00

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.
13,711 questions
0 comments No comments
{count} votes

1 answer

Sort by: Most helpful
  1. Siddharth Gautam 860 Reputation points
    2023-03-31T13:00:43.3333333+00:00

    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:

    https://github.com/microsoftgraph/msgraph-sdk-dotnet/issues/1368

    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.


Your answer

Answers can be marked as Accepted Answers by the question author, which helps users to know the answer solved the author's problem.