Uwe Keim
Uwe Keim

Reputation: 40726

Erroneous email receiver display when using German umlauts and a comma in name

Using the MailMessage class in .NET 4, I found an issue today that I'm unable to resolve so far. Please see the following code:

using (var message = new MailMessage())
{
    message.From = new MailAddress(@"[email protected]", "Uwe Keim");
    message.Bcc.Add(new MailAddress(@"[email protected]", "Uwe Keim"));

    // This fails (see screenshot).
    /*1*/ message.To.Add(new MailAddress(@"[email protected]", "Müller, Fred"));

    // This succeeds.
    /*2*/ message.To.Add(new MailAddress(@"[email protected]", "Fred Müller"));

    // This also succeeds.
    /*3*/ message.To.Add(new MailAddress(@"[email protected]", "Muller, Fred"));

    message.Subject = "Test";
    message.Body = "Some text body.";

    new SmtpClient().Send(message);
}

This is a simple snippet so send an SMTP message. Mutually trying the lines /*1*/, /*2*/ and /*3*/, the behavior differs:

Whenever a receiver ("To") name contains a German umlaut (i.e. "Ä", "Ö" or "Ü") and a comma (i.e. ","), the receiver sees damaged text in the email message he receives:

enter image description here

As you can see in the above screenshot (taken from Outlook 2010), there is a cryptic "=?utf-8?Q?M=C3=BCller" in the "To:" line.

Leaving out the comma or removing the German umlaut fixes this. I've tried both Exchange 2003 and hmailserver to get the same result.

My question is:

Is anyone aware of this behaviour and has a solution to it?

Update 1:

As suggested by user Adam Maras, I fired up Microsoft Network Monitor while sending the email message.

To me, it seems that the MailMessage class (or the SmtpClient class?) is already doing it wrong:

enter image description here

Upvotes: 8

Views: 3279

Answers (3)

Remy
Remy

Reputation: 12693

We actually had similar issues. Mainly with the Subject though. One step in the right direction was MailMergeLib:

http://www.codeproject.com/KB/IP/MailMergeLib.aspx

You could give that a try, but it didn't solve all our issues. Now we switched to Aspose.Email. It's better but still not perfect, we still have garbeled subject, but now only on Mac and iPhones, but they are working on a bugfix.

http://www.aspose.com/categories/.net-components/aspose.email-for-.net/default.aspx

You can try it for free. There are other email libraries on the net.
http://www.chilkatsoft.com/products.asp

Would be very intersted if you figure out something more.

Upvotes: 0

Adam Maras
Adam Maras

Reputation: 26843

So, after some digging, I came across Microsoft Support article 2576045: FIX: Email client does not support a name in a delivery address field that is encoded by the MailMessage class in the .NET Framework 4 if the name contains a non-ASCII character.

It appears that, when writing out an address that contains Unicode characters, the MailMessage class does not correctly encode something. I certainly can't tell you what it is based on the KB article's information, but whatever it is, it's enough to make downstream readers choke on the headers.

Upvotes: 4

Bastian
Bastian

Reputation: 10433

E-mail headers have to be us-ascii (7-bit), using umlauts need encoding as discribed in rfc2047. There are different ways to encode the strings and it looks like outlook or your mailserver won't understand the utf8 encoding.

You could try to mime encode the address yourself using iso-8859-1.

edit: I just checked the documentation at http://msdn.microsoft.com/en-us/library/system.net.mail.mailaddress.aspx

have you tried using MailAddress(String, String, Encoding) ?

Upvotes: 2

Related Questions