Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Get All Email Messages with Microsoft Graph - version 5.2.0 or above

The original code that I have is:

   var messages = await graphClient.Users["[email protected]"].MailFolders[folderName].Messages.GetAsync();

And I'm using Microsoft.Graph 5.2.0. Unfortunately, this only returns 10 emails at a time.

I tried the code that was posted to answer this question: Get all email message using Microsoft Graph API in c#. But, I'm having a problem with .Request method not being available. Here is the code that I am referring to:

var client = new GraphServiceClient(authenticationProvider);
var messages = await client.Users["[email protected]"].Messages
     .Request()
     .Top(100)
     .GetAsync();

When I code that way. the .Request() is showing red squiggly saying MailFolderItemRequestBuilder does not contain a definition for 'Request'. Even upgrading to Microsoft.Graph 5.5.0 did not help.

Could someone please help me out?

like image 983
Yogi Avatar asked Sep 02 '25 13:09

Yogi


1 Answers

In v5 you can specify the page size this way

var messages = await graphClient.Users["[email protected]"]
            .MailFolders[folderName]
            .Messages
            .GetAsync(x =>
            {
                x.QueryParameters.Top = 100;
            });

Other query options like Select, Filter, etc. are set with similar code.

Resources:

Query parameter options

like image 180
user2250152 Avatar answered Sep 05 '25 16:09

user2250152