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

SAC_535 36 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
Microsoft Graph
A Microsoft programmability model that exposes REST APIs and client libraries to access data on Microsoft 365 services.
11,423 questions
0 comments No comments
{count} votes

3 answers

Sort by: Most helpful
  1. Vicky Kumar (Mindtree Consulting PVT LTD) 1,166 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,711 Reputation points Microsoft Vendor

    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 40,231 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.