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:
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: