+2 votes

Subject is encoded by default but when I use AddCustomHeader it does not encode swedish characters like åäö which causes the server to reject the email.

How do we get Mail.Dll to encode the custom header using either UTF-8 of ISO-8859-1

Example on how it should look.

X-company: =?iso-8859-1?Q?V=E5rd?=

by

1 Answer

0 votes

It seems you are confusing several things:

1.
Generally email headers should contain only ASCII data, thus when trying to store non-ascii data/text, you need to use some 'tricks', like encoded words:
=?utf-8?Q?V=E5rd?=

2.
iso-8859-1 is an 8-bit single-byte encoding intended for Western European languages.

3.
UTF-8 is a character encoding capable of encoding all possible characters, or code points, defined by Unicode.

4.
Please note that custom headers ('X-') don't support encoded words by default, so no client is going to parse and decode them automatically.

5.
Use HeaderEncoder class:

string encoded = new HeaderEncoder.Encode("hello åäö");
by (298k points)
Hi

Ok, that was what I was looking for.

Our old component did that encoding by default and I did not find any example for it.
(The old failed in other respects)
...