Search code examples
outlookmicrosoft-graph-apioutlook-restapi

Identifying DSN (Delivery Status Notifications) or NDR (Non Delivery Reports) and the failed recipients in Microsoft Graph / Outlook REST API


I found several questions here about detecting mail status in various mail servers, but still it's unclear how to do it using Outlook REST API.

In documentation we can see the response for request:

GET https://graph.microsoft.com/v1.0/me/messages/AAMkADhMGAAA=

But it seems like the answer doesn't have a field, which contains such information. I also looked into request for headers:

https://graph.microsoft.com/v1.0/me/mailfolders/inbox/messages?$select=subject,internetMessageHeaders

Unfortunately, there was no header like X-Failed-Recipients.

Are there any ways to get delivery status and/or failed recipients using Outlook API?


Solution

  • My approach to this was getting message details and the internetMessageHeaders as you have done.

    • First I check for header Content-Type value multipart/report which denotes a DSN (delivery status notification), see RFC 3461.

      • GET https://graph.microsoft.com/v1.0/me/messages/<id>?$select=internetMessageHeaders
    • Then I get the toRecipients property of the message which contains the email address of the recipient that failed.

      • GET https://graph.microsoft.com/v1.0/me/messages/<id>

    Note:

    • Not all mail servers follow RFC3461, so some DSN/NDR emails may slip through
    • I could not find any documentation saying that toRecipients always contains the value of the failed recipient, but so far I have yet to find an example to the contrary.