Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Add headers to outgoing smtp message that will exist in reply

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 ?

like image 211
ohadinho Avatar asked Jan 18 '26 09:01

ohadinho


1 Answers

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.

like image 59
Danny_ds Avatar answered Jan 20 '26 21:01

Danny_ds



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!