How to access shared mailboxes via IGraphClient

I am using the IGraphClient to fetch emails which works fine using aspose-email-21.1.3-jdk16.jar.
However i did not find any way to specify the user / sharedmailbox i want to query. I always get the access token owners mails.

Is there a way to access a shared mailboxes mails with IGraphClient?

@fxhak,
Thank you for your request. You can specify a user for a shared mailbox as below:

graphClient.setResource(ResourceType.Users);
graphClient.setResourceId("mailbox");
graphClient.listMessages("mailfolder")
// back to the current mailbox
graphClient.setResource(ResourceType.Me);

More samples: msgraph-java.zip (5.2 KB)
To our regret, the documentation is not ready yet. It will be published later.

@Andrey_Potapov That is what I was looking for! Thank you for the fast reply.

Hi Andrey,

I want to list messages of custom folder, this method lists only pre-defined folders not custom ones graphClient.listMessages(GraphKnownFolders.SentItems).

If I pass folder name as string “graphClient.listMessages(“NewFolder”)” it is giving below error.

Exception in thread “main” class com.aspose.email.system.exceptions.FormatException: The string contains invalid characters.

And also want to know how to pass the pre-defined folder names as string to listMessages().

Hello @jashuvaprasannakumar.kotte,

You need to use the listFolders() method to get the custom folder id:

// List Sub Folders 
//GraphFolderInfoCollection folderInfoCol = client.listFolders(GraphKnownFolders.Inbox);
// List Root Folders
GraphFolderInfoCollection folderInfoCol = client.listFolders();
for (GraphFolderInfo folderInfo : folderInfoCol) {
	// check display name and fetch messages
    if (folderInfo.getDisplayName().equals("myFolder")) {
        client.listMessages(folderInfo.getItemId());
    }
}

Thanks for the reply

Hi @sergey.vivsiuk,

I am facing one issue, I am trying to get inbox sub-folders list, but size is limiting to 10 only. Inbox has 23 folders but when I try to get the size using “folders.size();” method it is giving 10 only even though it has 23 sub-folders. Could you please help me in this.

GraphFolderInfoCollection folders = client.listFolders(GraphKnownFolders.Inbox);

@jashuvaprasannakumar.kotte
We have opened the following new ticket(s) in our internal issue tracking system and will deliver their fixes according to the terms mentioned in Free Support Policies.

Issue ID(s): EMAILJAVA-35183

You can obtain Paid Support Services if you need support on a priority basis, along with the direct access to our Paid Support management team.

@jashuvaprasannakumar.kotte,

The issue has been fixed in the 21.10 release

@sergey.vivsiuk,

Thanks for the solution. That worked.

@jashuvaprasannakumar.kotte,

Thank you for the feedback.