Search code examples
outlookmicrosoft-graph-apiexchange-server

What's the best way to get all messages for all users?


After doing some reading through the docs it seems like if you wanted to read all messages for all users in a Microsoft Exchange Online tenancy you need to do something like:

  1. Get all users
  2. For each user, get all mailFolders
  3. For each mailFolder, get all messages

Is this the best way to get all messages, or is there some way to return all messages regardless of the mailFolder they are in?


Solution

  • You can omit the second point and get all the messages in a user's mailbox by calling the endpoint:

    GET /users/{id|userPrincipalName}/messages
    

    Resource:

    List messages