Home » SQL Server

special characters in email addresses


Is there a manner to use e-mail addresses with special characters with the System.Net.Mail.MailAddress class?
For example françois.démontè@test.com.

Because mostly you get an System.FormatException:
System.FormatException: The specified string is not in the form required for an e-mail address.
   at System.Net.Mime.MailBnfHelper.ReadMailAddress(String data, Int32& offset, String& displayName)
   at System.Net.Mail.MailAddress.ParseValue(String address)
   at System.Net.Mail.MailAddress..ctor(String address, String displayName, Encoding displayNameEncoding)

Someone a solution for this problem?
Thanks in advance.

Kind regards,


3 Answers Found


Answer 1

Try this:

new MailAddress("françois.démontè@test.com","françois démontè", Encoding.Default)

or switch it to Encoding.Unicode



Answer 2

This is definitely a tricky part.

I set as value for the To address  françois.démontè@test.com and my real address and I receive the mail  (at my real inbox), but there is just one address in the To field and that is my real address.

So I can't control the accomplishment of the mail sent to françois.démontè@test.com.
I want to test it with a real address but I can't create one at my mailhost with those characters.

One good thing is that there are no exceptions are thrown.




Answer 3

Hi crmkr,


Welcome to MSDN Forums!


I think you need use this Encoding Class to change the string format, and then use it in the constructor.

string s = "test string";

string utf8_string = [dest Encoding].GetString([original Encoding].GetBytes(s));


PS:@Stuart Phillips

The third parameter is used to encoding  the display name not the email  address.

MailAddress Constructor (String, String, Encoding)



Can you share your code? We want to know your method. If you put the email address  in the constructor directly or after change the encoding?

Thank you.


If you have anything unclear, please feel free to let me know.


Have a nice weekend!



Please remember to click “Mark as Answer” on the post that helps you, and to click “Unmark as Answer” if a marked post does not actually answer your question. This can be beneficial to the others community members reading the thread.



<< Previous      Next >>

Microsoft   |   Windows   |   Visual Studio   |   Sharepoint   |   Azure