Why doesn't MailAddress quote DisplayName when there is a comma?

We recently migrated from .NET 2 to .NET 4, and the System.Net.Mail.MailAddress class gave me a headache. Previously, if I had an email ( joe@example.com ) and display name (Joe Smith, CEO®), you could do:

MailAddress from = new MailAddress(" joe@example.com ", "Joe Smith, CEO®"); 

And you will get a properly formatted "Joe Smith, CEO" < joe@example.com > when sending via email. It was viewable / etc. all senders.

With .NET 4, Outlook / Exchange tidies up how it is encoded, dividing it into Comma: < =?utf-8?Q?Joe@gwm.example.com >, CEO=C2=AE?= < joe@example.com > , because of which it will not decode correctly .

From Microsoft :

A comma is used to separate items in the mailing list. As a result, the comma should not be used in unquoted display names in a list.

Which is good, but when you do:

 MailAddress from = new MailAddress(" joe@example.com ", "\"Joe Smith, CEO®\""); 

Quotes are deprived because;

This method removes surrounding quotes that are not displayed. DisplayName property.

So, how do you tell MailAddress that the comma that it does not want should be quoted without adding extra space (for example, "\ u200B \" Joe ... \ ""), which indentes the address in the mail reader?

UPDATE

Microsoft answer (see response comments for link):

Submitted by Microsoft on 8/17/2011 - Thanks for your feedback. This is a well-known issue, and the patch is currently created for .NET 4.0. To obtain the hotfix, contact Microsoft Support directly regarding KB 2576045 .

+4
source share
1 answer

did not test, but tried

  MailAddress from = new MailAddress(" joe@nospam.com ", "Joe Smith\",\" CEO®"); 

EDIT is another option:

  MailAddress from = new MailAddress(" joe@nospam.com ", "Joe Smith\x2C CEO®"); 
+1
source

All Articles