Hi @SAC_535
I wrote a C# sample for you that gets the details of a message by message id. I'm using the client credential flow to get the token, before that you need to grant the Mail.ReadBasic.All
application permission to your application.
using Microsoft.Graph;
using Microsoft.Graph.Auth;
using Microsoft.Identity.Client;
using Newtonsoft.Json;
namespace test1
{
class Program
{
static async System.Threading.Tasks.Task Main(string[] args)
{
IConfidentialClientApplication app;
app = ConfidentialClientApplicationBuilder.Create("{client id}")
.WithClientSecret("{client secret}")
//.WithRedirectUri("https://jwt.ms")
.WithAuthority(new Uri("https://login.microsoftonline.com/{tenant id}"))
.Build();
AuthenticationResult result;
string[] scopes = new string[] { "https://graph.microsoft.com/.default" };
result = await app.AcquireTokenForClient(scopes).ExecuteAsync();
/*string accesstoken = result.AccessToken;
Console.WriteLine(accesstoken);*/
ClientCredentialProvider authProvider = new ClientCredentialProvider(app);
GraphServiceClient graphClient = new GraphServiceClient(authProvider);
var message = await graphClient.Users["{user id}"].Messages["{message id}"]
.Request()
.GetAsync();
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.