Search code examples
azure-functionsmicrosoft-graph-apiwebhooksmicrosoft-graph-mailexchange-online

Reading mail content from m365 group mailbox


I'm developing a solution in which I want to react on incoming mails from a group mailbox (not a shared mailbox) and store the content of the mail, including attachments, in a SharePoint library.

I have a webhook subscribing the group mailbox and triggers an Azure Function. In the Azure Function we can retrieve attachments from the post-endpoint using the Graph API:

https://graph.microsoft.com/v1.0/groups/{group-id}/conversations/{conversation-id}/threads/{thread-id}/posts/{post-id}/attachments

However, we do not have access to the mail itself through the Graph API. The body of the post contains only a snippet of the mail forwarded to the group mailbox. It appears that only the last part of the mail is included and the rest of the conversation history is omitted.

Another approach considered was forwarding the mail (post) to a service account for processing. This approach works in principle since we can retrieve the email content from a regular mailbox using the Graph API. However, this option is not feasible for the customer.

Another attempted approach was processing it through a Power Automate Flow. However, we face the same limitations here as well. We do not have access to the full email content.

The solution must also support dragging and dropping the mail from the user's mailbox to the group mailbox via Outlook.

Can anyone provide a solution for this problem?


Solution

  • Are you after any specific properties on the Message? the Post strongly typed objects are a pretty limited in what properties you can display but they allow you to specify singleValueExtendedProperties so you can always get the underlying exchange extended property (on the message) eg to get the Subject via the extended property you can use

    https://graph.microsoft.com/v1.0/groups/../threads/A...A=?$expand=singleValueExtendedProperties($filter=id eq 'String 0x0037')
    

    To get the HTMLBody you can use https://learn.microsoft.com/en-us/office/client-developer/outlook/mapi/pidtaghtml-canonical-property this will return the body base64 encoded

     https://graph.microsoft.com/v1.0/groups/../threads/A...A=?$expand=singleValueExtendedProperties($filter=id eq 'Binary 0x1013')