+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?=


1 Answer

0 votes

It seems you are confusing several things:

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:

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

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

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

Use HeaderEncoder class:

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

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)