Reputation: 75
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?
Upvotes: 4
Views: 2025
Reputation: 1
Use the following select statement: toRecipients
Example:
GET https://graph.microsoft.com/v1.0/me/messages/<id>/?$select=subject,bodyPreview,from,receivedDateTime,toRecipients
Response:
{
"receivedDateTime": "2024-12-04T01:32:05Z",
"subject": "Undeliverable: XYZ",
"bodyPreview": "Your message to [email protected] couldn't be delivered.....",
"from": {
"emailAddress": {
"name": "Microsoft Outlook",
"address": "[email protected]"
}
},
"toRecipients": [
{
"emailAddress": {
"name": "XYZ",
"address": "[email protected]"
}
}
]
}
For NDRs, you can then evaluate the toRecipients property - this contains the original destination address for NDRs.
EDIT: Unfortunately, this solution does not work reliably. Depending on which mail server sends back the NDR, these fields are filled correctly.
Upvotes: 0
Reputation: 1
I did try the mention solution, but It worked when I add extra '/' in the link
GET https://graph.microsoft.com/v1.0/me/messages/<id>/?$select=internetMessageHeaders
Upvotes: 0
Reputation: 8038
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:
toRecipients
always contains the value of the failed recipient, but so far I have yet to find an example to the contrary.Upvotes: 4