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.

One thought on “UTF-8 email, body and title encoding

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.