UTF-8 email, body and title encoding

When sending an email with an application or sendmail, using an UTF-8 encoding, some attributes must be given if you expect the email to be displayed correctly by the reader.

To start, to get the right display in the body of the email, you need to specify the encoding in the header fields by adding :

Content-Type: text/plain; charset="UTF-8" 
Content-Transfer-Encoding: 8bit

The subject is not proceed using this attribute and it must be written in a different way to be interpreted correctly:

Subject: =?utf-8?Q?éssai=20de=20sujet?=

Here, the “?utf-8?Q?” indicates what encoding to be used in the tittle, then it is followed by the title itsleft “Q” indicates that the title is in plain text. The limit of this is that the title can’t contain space, tabs or ? without being escaped firstly. The Title is ended by termination sequence “?=

The other solution to manage title more easily is to use a base64 encoding with the “B” encoding type instead of “Q”

Subject: =?utf-8?B?base64EncodedTitle?=

This way is more easy to encode if your system handle a base64 encoding function.

This entry was posted in Programming and tagged , . Bookmark the permalink.

One Response to UTF-8 email, body and title encoding

  1. Florian P says:

    Hey Paul, you forgot the source : RFC-2047 ^^

    And RFC-2045 is also interesting…

Leave a Reply

Your email address will not be published. Required fields are marked *

This site uses Akismet to reduce spam. Learn how your comment data is processed.