3

I need to create a correlation between an outgoing e-mail to a reply e-mail without changing the subject or body.

I've tried to add some headers to an SMTP outgoing mail:

var outgoingMessage = new System.Net.Mail.MailMessage();
mail.Headers.Add("Tag","MyNewTag");
mail.Headers.Add("CorrelationID","MyNewCorrID");

Unfortunately, when replying to that email message - those headers are gone.

Is there any way to correlate between outgoing and incoming message without interfering subject or body ?

Danny_ds
  • 11,201
  • 1
  • 24
  • 46
ohadinho
  • 6,894
  • 16
  • 71
  • 124

1 Answers1

2

For the headers you should probably use X-headers instead:

mail.Headers.Add("X-Tag","MyNewTag");
mail.Headers.Add("X-CorrelationID","MyNewCorrID");

To correlate between outgoing and incoming message without interfering subject or body, you could also check the References: header (only with reply, not with forward).

This header contains the Message-ID('s) of the originating messages:

References: <some-id@domain>

There is also the In-Reply-To header.

To add more information you could even customize the outgoing Message-ID.

Maybe the Thread-Index header could be helpful too.

Danny_ds
  • 11,201
  • 1
  • 24
  • 46
  • I used References and it works great. Even when forward a message. – ohadinho Jul 03 '18 at 12:56
  • 1
    @ohadinho Good to hear. Preserving references when forwarding might depend on the e-mail client though. PS, there is also the `In-Reply-To` header (added to the answer). – Danny_ds Jul 03 '18 at 13:34
  • unfortunately, none of these solutions work when replying from gmail client. Any ideas? – ohadinho Jul 09 '18 at 13:33
  • @ohadinho If the client decides not to include/preserve any of these headers in a reply then there's not much that can be done about it I think. Doesn't gmail client at least preserve the `Thread-Index` header? Or are there any other headers in a reply from gmail? (I don't have gmail so I can't test this) - The only remaining option then would be to keep a local list with `from` and/or `to` and `subject` for example, but even then those fields could be changed when replying. – Danny_ds Jul 09 '18 at 14:26