I have a system that sends out mail to the users. The emails are constructed in one application, then another service sends out documents to the respective receipients. The issue arises when the email is not delivered(e.g. email address doesn't exist). The SMTP client
that sends the mail considers the mail sent, as I understand it should, and eventually a Non-Delivery Report(NDR
) is returned, through exchange mail server, to the From
address. The issue I'm having is how to deal with these undelivered mails. My first thought was to use a special mailbox for the mails, and when a NDR arrives, compute it, and mark the invoice(for example) as having an error with the mail address, in the backend database.
However, after searching about doing custom NDRs messages, it seems that the most "knowledge" the NDR has of the undelivered mail is the receipient and message headers. Initially I tried seeing if the NDR could contain the message, such that some tracking id could be added to the mail sent out, such that going through the NDR would allow a program to set the invoices delivery status to a delivery error status.
I've tried looking for how others deal with this without success. I found this information on generating new NDRs: https://learn.microsoft.com/en-us/exchange/mail-flow/non-delivery-reports-and-bounce-messages/ndr-procedures?view=exchserver-2019 but it doesn't seem to help the situation.
Is there a way to configure exchange mail server to make NDRs contain the original message, or is there a way to add some tracking to the mail headers?
Or alternately and more generally, is there a different way to approach this problem?