Sami
Sami

Reputation: 101

How to maintain/preserve Custom Email Headers(X-header) when replying

i am using following code to send an email from my .NET application ,here i have added custom header X-Company. When the email is received i get this custom header properly but whenever i reply/forward this mail Custom Headers not getting back.

MailMessage message = new MailMessage(From, To);                  
                message.Headers.Add("X-Company","xyz");                
                message.Body = emailMessage.ToString();
                message.Subject = Subject;                
                message.IsBodyHtml = true;               
                smtp.Send(message);

Upvotes: 10

Views: 4589

Answers (3)

nonano
nonano

Reputation: 1

As mentioned by Parapura rajkumar, including a hidden html element in the email is the best way to go about this because custom headers will not be preserved across all email providers.

Email providers will often break/remove html parameters, I've found the most reliable way to smuggle parameters through is to include them as image query parameters.

Below is an example of an invisible image to append to the body of the email. You can replace the wikimedia image with your own resource and smuggle parameters through as query parameters. When the user replies, you should be able to parse this back out again. If you're hosting the URL, this has the added bonus of hitting your server when the email is opened, which can be used to determine when an email has been viewed.

<img src='https://upload.wikimedia.org/wikipedia/commons/c/ca/1x1.png?policyref={policyref}'  alt='' width='1' height='1' border='0' style='height: 1px; width: 1px; border-width: 0px; margin: 0px; padding: 0px;'>

Upvotes: 0

Asfand Iqbal
Asfand Iqbal

Reputation: 108

We had a similar situation where we supposed to send emails to customers and read them back and associated them with various activities.

During the research the the only HEADER we found that does not get replaced or Removed by the various email clients (Outook, Yahoo, Gmail etc.) was "XREF". We have thoroughly tested it and it has been working since we first introduced it.

Upvotes: 0

parapura rajkumar
parapura rajkumar

Reputation: 24413

This would be very hard to do across all email clients as they are free to strip away headers that they deem unnecessary when you do a reply to.

If your sole goal is to insert some key value pair and have it return back to you whenever somebody does a reply to, As you are doing HTML email you can have a hidden html element in which you have your custom header information.

Upvotes: 1

Related Questions