our team needs somehow to detect from our python code messages that got bounced (permanently) and add them to our bounce list in order to not send them in the future anymore. So for example when we send a notification to a non-existent mailbox expected behavior is to receive a bounce mail from the message system which will provide some info for the user and admin diagnostic info. In order to detect permanently bounced messages we tried to use the python library which is called flufl.bounce and during the investigation I was able to detect bounce messages when I scanned my personal Gmail account via IMAP and the library worked perfectly. However, it’s not possible to use IMAP in our use case for our shared mailbox in azure Since basic authentication is not supported anymore and OAuth client credential flow hasn’t been implemented yet for IMAP. Therefore instead of IMAP, we are using Microsoft graph API which supports client credential flow and we are able to get messages from our mailbox. However, the DSN detector is flufl.bounce library does not recognize such messages as bounced even though from admin diagnostic information it’s clear that message is bounced. I've made some investigation and found out that the message does not include the following headers which should present in response in order to recognize it as a bounce. For example:
Content-Type: message/delivery-status
Reporting-MTA: dns; googlemail.com
Arrival-Date: Tue, 26 Oct 2021 02:35:28 -0700 (PDT)
X-Original-Message-ID: <****>
Final-Recipient: rfc822; ********************
Action: failed
Status: 5.1.1
Diagnostic-Code: SMTP; 550-5.1.1 The email account that you tried to reach does not exist. Please try
550-5.1.1 double-checking the recipient's email address for typos or
550-5.1.1 unnecessary spaces. Learn more at
550 5.1.1 https://support.google.com/mail/?p=NoSuchUser
Last-Attempt-Date: Tue, 26 Oct 2021 02:35:28 -0700 (PDT)
When I check bounce messages via outlook view source I can find this header, however, graph api response does not contain them. I tried to fetch the eml version of mail via graph api however I didn't find these headers. Is it possible to add them to the response somehow? or should we wait till client credential flow for IMAP will be released?
Thanks for reaching out. To my knowledge, fetching these headers is not currently supported by MS Graph, would you consider filing a feature request on the Microsoft developer platform so this can be looked into?
In the meantime, you might look into using Microsoft Outlook Messaging API (MAPI) to detect bounced messages.
Let me know whether this helps and if you have further questions.