Get outlook email message details from message id and graph token in C#

SAC_535 26 Reputation points

I have message id and Graph access token need to get message details from this in C# dotNet.

How to call below get method in C# to get message details
GET["User Id"]/Messages["Message id"]
Accept: application/json
Authorization: Bearer <token>

Microsoft Graph Applications API
Microsoft Graph Applications API
A Microsoft API that enables you to manage these resources and actions related to applications in Azure Active Directory.
561 questions
Microsoft Graph Mail API
Microsoft Graph Mail API
A Microsoft API that supports accessing data in users' primary mailboxes and in shared mailboxes.
800 questions
Microsoft Graph SDK
Microsoft Graph SDK
A Microsoft software developer kit designed to simplify building high-quality, efficient, and resilient applications that access Microsoft Graph.
883 questions
0 comments No comments
{count} votes

3 answers

Sort by: Most helpful
  1. Vicky Kumar (Mindtree Consulting PVT LTD) 1,146 Reputation points Microsoft Employee

    If you are trying to get the messages with C# code , you should try with below code

    GraphServiceClient graphClient = new GraphServiceClient( authProvider );  
    var message = await graphClient.Me.Messages["{message-id}"]  

    Ref doc -

    Git -

    Hope this helps


    0 comments No comments

  2. Srinivasa Rao Darna 6,461 Reputation points

    Hello @SAC_535 ,

    A sample snippet:

    var message = await graphClient.Users["{user-id}"].Messages["{message-id}"]  


    Hope this helps.
    If the answer is helpful, please click "Accept Answer" and kindly upvote it. If you have extra questions about this answer, please click "Comment".

    0 comments No comments

  3. CarlZhao-MSFT 23,361 Reputation points

    Hi @SAC_535

    You can call the endpoint using the C# Graph SDK, and since /users/{user id} only supports application contexts, you need to use the client credentials flow to get a token. Please refer to the complete code:

    using Azure.Identity;   
    using Microsoft.Graph;  
    using Newtonsoft.Json;  
    var scopes = new[] { "" };  
    var tenantId = "{tenant id}";  
    // Values from app registration  
    var clientId = " {client id}";  
    var clientSecret = "{client secret}";  
    // using Azure.Identity;  
    var options = new TokenCredentialOptions  
        AuthorityHost = AzureAuthorityHosts.AzurePublicCloud  
    var clientSecretCredential = new ClientSecretCredential(  
        tenantId, clientId, clientSecret, options);  
    var graphClient = new GraphServiceClient(clientSecretCredential, scopes);  
    var message = await graphClient.Users["{user id}"].Messages["{message id}"]  
    Console.WriteLine("message:" + JsonConvert.SerializeObject(message));  


    If the answer is helpful, please click "Accept Answer" and kindly upvote it. If you have extra questions about this answer, please click "Comment".
    Note: Please follow the steps in our documentation to enable e-mail notifications if you want to receive the related email notification for this thread.