microsoft-graph-apimicrosoft-graph-sdks

Graph Subscription Email Resource For All Emails


I am working on a system that allows the user to log their email conversation to our CRM. This uses MS Graph subscriptions that create a subscription to a given email conversation. We then process the Graph notifications. When creating the subscriptions we set the resource like this:

/users/{id}/mailFolders('inbox')/messages
/users/{id}/mailFolders('sentItems')/messages

This gives us notifications for when the user sends or receives an email on that conversation thread. This works great, but we discovered that if the user has a rule set up to send items with a certain subject to a different folder, when receiving a new email that they have subscribed to, we don't receive a notification. I am guessing that this is due to us subscribing to the inbox and sentitems but not the custom folder that they have their rule directed to. I noticed that there is also a way to set the resource as:

/users/{id}/messages

Can someone tell me whether this will set up the subscription to receive emails from all folders? If this is the case, we wouldn't want to receive notification for example when the user deletes and email.

Additionally, we currently create 2 separate subscriptions. Is there a way to create a subscription for more than 1 resource (e.g.inbox and sentitems) under the same subscription?

thanks


Solution

  • The resource path users/{id}/messages is just a shortcut to the one with the inbox mark folder. A subscription to it will only notify you of emails going to that folder.

    A subscription only allows you to subscribe to one resource at a time. You could use JSON batching to create/maintain multiple subscriptions in the same call, but that would only be beneficial to reduce the number of http requests.

    You'll need to subscribe to each folder you want to get notified for, a request to users/{id}/mailFolders should give you a list of the folders for the inbox.