'How to identify whether an incoming email a reply to a previously sent one or just a separate incoming one?

I'm building a system which will send email automatically. To some of them the system will expect replies. Also a user will be able to simply send an email directly to the system, any time (not as a reply).

There's one single email which will both send and receive emails. That is, there won't be, probably, any unique email assigned to a user with +

Question: when the system receives an email, how will it be determine with 100% accuracy whether it's a reply to an earlier sent one, or simply a separate, sent out of the blue, one?

Note that "Re: <subject>" isn't a reliable way at all. Neither could it be the body, for both body and subject can be removed or altered by a user.

I think I should utilize Message-ID, In-Reply-To and References somehow. But how precisely?

Also, a user theoretically can use any email client whatsoever.



Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source