Search code examples
c#htmlencodingoutlookcontent-encoding

Is Content-Transfer-Encoding an HTML header?


We are sending an automated email with mail's body in HTML format and we are receiving the email content twice in the body.Once with this header

MIME-Version: 1.0
Content-Type: multipart/alternative;
    boundary="----=_NextPart_000_00F5_01D2C509.C9598370"
X-Mailer: Microsoft Outlook 16.0
Thread-Index: AdLE260N6ZrXujJMTE6odOelzNRIhw==
Content-Language: en-us

This is a multipart message in MIME format.

------=_NextPart_000_00F5_01D2C509.C9598370
Content-Type: text/plain;
    charset="us-ascii"
Content-Transfer-Encoding: 7bit

and then with this header

------=_NextPart_000_00F5_01D2C509.C9598370
Content-Type: text/html;
    charset="us-ascii"
Content-Transfer-Encoding: quoted-printable

also tried having the Content-Transfer-Encoding header in html having one of these values "BASE64" / "QUOTED-PRINTABLE" / "8BIT" / "7BIT" / "BINARY" / "x-token". But still having the same headers of MIME in the received mail.
So firstly, Is Content-Transfer-Encoding an HTML header? If yes, will changing the value of this header to a correct value will fix this issue?


Solution

  • Is Content-Transfer-Encoding an HTML header?

    No, it is not related to HTML or to to be exact "just HTML". "Content-Transfer-Encoding" is the header of the particular content of the MIME (it may be HTML content as well) which indicate encoding of this content when added to MIME to transfer this content. I know it sounds a bit weird, content, content and content, but may be this resource would help you to understand better: Content-Transfer-Encoding Header Field. The Content-Transfer-Encoding is designed to specify an invertible mapping between the "native" representation of a type of data and a representation that can be readily exchanged using 7 bit mail transport protocols. But enough theory, lets do some real world example you have ...

    You compose your message with Outlook in HTML format. When message will leave Exchange environment (sent out) it will be converted to MIME to travel through Internet. At this point your HTML will be encoded with appropriate, to the content of this HTML, type and Content-Transfer-Encoding header will be added to this content, so the recipient of this message able to convert this content back to original HTML by decoding the content. I hope this clear now.

    We are sending an automated email with mail's body in HTML format and we are receiving the email content twice in the body

    According to rfc2046 for Multipurpose Internet Mail Extensions (MIME) Alternative Subtypes of the same body (your HTML content) were created at the time message was converted into MIME and appropreate header was added to indicate that "Content-Type: multipart/alternative;". Each of the body parts is an "alternative" version of the same information. This means you have "text/plain" content, which represent nothing else as strip off version of your HTML to bare text. This content is alternative to HTML and has it's own Content-Transfer-Encoding header based on the content. This content may be used by the recipients who do not have ability to render HTML.