I am trying to find a way I can use email headers to tie an email back to the database. Ideally, I would be able to send out an email and attach a custom email header with the ID of the database object, and then when I get a reply back from the email we would still have that header so we can match it. Does anyone know if this is possible? I'm absolutely fine with the code side of how headers work it's just how they actually work in the real world.
-
yes, [but](https://serverfault.com/a/243388/387902). related, near duplicate: https://stackoverflow.com/q/10684097/1132334 and I recommend to look up [IETF RFC 822](https://tools.ietf.org/html/rfc822) – Cee McSharpface Jun 13 '18 at 09:23
1 Answers
It is possible, but whether it will work or not for a particular recipient is not under your control.
IETF RFC 822 stipulates the use of an X-
prefix for vendor- and application specific headers, much like indie MIME types could be allocated.
Mail relays and mail clients will leave or remove such headers at their discretion. You have no means to force those headers to be retained in a reply or forward scenario.
In real-world applications that have the same requirement to refer to a database Id value (support ticket portals coming to my mind first), it is often seen that they include the GUID in the subject line and mention in the body text that the recipient should not remove or change that value lest they disrupt the automated processing of replies.
This approach is superior to the x-header in many ways:
- it does not hide the fact that there is additional information transported on behalf of the recipient
- it will not cause spam filters, mail relays and mail clients to automatically strip that information without the sender or the recipient noticing
- it leaves the recipient free to decide if they want to forward or reply to a mailbox different from the sender's, including or excluding the Id as they see fit
If you're going to stick with the headers, look into Thread-Index
and Thread-Topic
. Here, as so often, Microsoft has introduced application-defined attributes without the standard prefix, and there is a chance that these are transported back with replies more reliably than x-headers just because they've been around for a longer time - ymmv.

- 1
- 1

- 8,493
- 3
- 36
- 77