I am trying to group emails sent and received by threads in my Delphi XE2 application. I use Indy 10 components and the idea is to link the email unique Message-IDs with the In-Reply-Tos.
- First step is to store the Message-ID of the very first email of the thread sent out. This is the email that starts the thread.
- Second step is to store, for the emails received, the email In-Reply-Tos field. By linking Message-ID and In-Reply-To I can compose the email thread.
The first step is achieved with the following code:
FIdMessage1.MsgId:='Unique ID';
FIdMessage1.ExtraHeaders.Values['Message-Id'] := FIdMessage1.MsgId;
Here the email is sent out with 'Unique ID' in the field Message-ID of the email correctly.
When the recipient of this email replies the In-Reply-Tos is not 'Unique ID' any longer but something like '<-9999999999999999999@unknownmsgid>'. It seems that the recipient email server override my Message-ID.
What can I do in order the server not override my Message-ID ? If my approach is wrong what can I do in order to organize emails sent/received in threads ?
Organizing emails by subject is not an option because there may be different email threads with the same subject.
****UPDATE****
I have solved, temporary, this issue.
I delete the code I mention in the first step above then with this piece of code Get email headers from GMail's "Sent items" folder
This way I can retrieve the email I have just sent and with AMsgList[i].MsgId
I can see the email id.