Forum Discussion

anrm6's avatar
anrm6
New Member
11 months ago
Solved

Faster mail load from Exchange

Hi everyone, I’m working with Power Query and using the Exchange.Contents connector to access my Outlook mailbox. The issue is that my mailbox has over 400,000 emails, and Power Query tries to load ...
  • MarkLaf's avatar
    11 months ago

    You may want to look into querying your mail messages via Graph API.

     

    Some caveats:

    1. I have not used this directly in a while, so just going off memory / quick research / testing with Graph Explorer sample tenant.
    2. Graph integration with PBI is quite limited. Last I checked, though, you could still connect to personal mail through simple http calls and using PBI oauth. See MS party line on this: https://learn.microsoft.com/en-us/power-query/connecting-to-graph
    3. For a more enterprise solution, you may want to look into the MS recommended route of Graph Data Connect through Data Factory

     

    Connecting would look something like this:

     

    Web.Contents(
        "https://graph.microsoft.com/v1.0",
        [
            // can query me/mailFolders and nav via childFolders; eg me/mailFolders/<id>/childFolders/<id>/messages
            RelativePath = "me/mailFolders/inbox/messages", 
            Headers = [ accept = "application/json" ],
            Query = [
                #"$orderby" = "sentDateTime desc",
                // props list for select: https://learn.microsoft.com/en-us/graph/api/resources/message#properties
                #"$select" = "id,sentDateTime,from,subject,bodyPreview", 
                // eg filter to this year; datetime format is ISO 8601 (eg 2025-01-01T00:00:00Z)
                #"$filter" = "sentDateTime ge 2025-01-01", 
                #"$top" = "100" // I believe max is 1000 - adjust as needed for performance
            ]
        ]
    )

     

     

    Parse the response as JSON (Json.Document). You'll get a JSON record with fields:

    • value: list of records to upack with Table.FromRecords
    • @odataNextLink: if more records exist than specified in $top, this will give the REST url for next page of size $top