Your error seems to be thrown, only from the type of exception you shared I can't find the cause of the problem, I suggest you catch the error message to know the problem details.
If you're trying to list messages in a user's mailbox in an application-only context, then make sure to:
- The user is a work account (not a personal or guest account) and is in the current tenant.
- Make sure the target user has a Microsoft 365 license.
- Make sure the application has one of the Mail.ReadBasic.All, Mail.Read, or Mail.ReadWrite application permissions.
- Make sure your administrator has not configured application access policies to restrict application access to mailboxes.
I did a quick test locally with the graph SDK and it works fine:
Hope this helps.
If the reply is helpful, please click Accept Answer and kindly upvote it. If you have additional questions about this answer, please click Comment.