Hi @abhishek appu , I couldn't reproduce this issue on my end. Here's the code I ran successfully locally, hoping it would help you.
using Azure.Identity;
using Microsoft.Graph;
class Program
{
static async Task Main(string[] args)
{
await ReadEmail();
}
static async Task ReadEmail()
{
var scopes = new[] { "https://graph.microsoft.com/.default" };
var tenantId = "{YOUR_TENANTID}";
var clientId = "{YOUR_CLIENTID}";
var clientSecret = "{YOUR_CLIENTSECRET}";
var clientSecretCredential = new ClientSecretCredential(
tenantId, clientId, clientSecret);
var graphClient = new GraphServiceClient(clientSecretCredential, scopes);
var messages = await graphClient.Users["USER_ID"].MailFolders["Inbox"].Messages
.Request()
.GetAsync();
foreach (var message in messages.CurrentPage)
{
Console.WriteLine($"Message: {message.Subject ?? "NO SUBJECT"}");
Console.WriteLine($"From: {message.From?.EmailAddress?.Name}");
Console.WriteLine($"Status: {(message.IsRead!.Value ? "Read" : "Unread")}");
Console.WriteLine($"Received: {message.ReceivedDateTime?.ToLocalTime().ToString()}");
}
}
}
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.