Hi @Anns
You are getting this error because no Exchange Online mailbox is available to use. The Azure ad user for which you are trying to get messages do not have a valid M365 license.
Please provide the valid M365 License to the user.
Also, for more details please refer to this similar case.
Hope this helps.
If the answer is helpful, please click Accept Answer and kindly upvote. If you have any further questions about this answer, please click Comment.