We’ve recently migrated from .NET 2 to .NET 4 and the System.Net.Mail.MailAddress class is giving me a headache. Previously, if I had an email (joe@example.com) and a displayname (Joe Smith, CEO®) you could do:
MailAddress from = new MailAddress("joe@example.com", "Joe Smith, CEO®");
And you’d get a properly formatted "Joe Smith, CEO" <joe@example.com> when emailed. This was viewable/readable/etc. by all mailers.
With .NET 4 Outlook/Exchange are throwing a fit on how this is encoded, splitting it on the Comma: <=?utf-8?Q?Joe@gwm.example.com>, CEO=C2=AE?= <joe@example.com> which causes it to not be decoded properly.
A comma is used to separate elements in a list of mail addresses. As a
result, a comma should not be used in unquoted display names in a
list.
Which is fine, but when you do:
MailAddress from = new MailAddress("joe@example.com", "\"Joe Smith, CEO®\"");
The quotes are stripped because;
This method removes surrounding quotes not displayed by the
DisplayName property.
So how do you tell MailAddress that the comma it doesn’t want should be quoted, without adding an extra space (such as “\u200B\”Joe…\””) that makes the address indent in the mail reader?
UPDATE
Microsoft’s Answer (see response comments for link):
Posted by Microsoft on 8/17/2011 — Thank you for your
feedback. This is a well known issue and a patch is currently being
created for .NET 4.0. To obtain the patch please contact Microsoft
Support directly regarding KB 2576045.
didn’t test it but try
EDIT – another option: