Unicode character in email not throwing exception

301 views Asked by At

I have an email address with unicode character. It is not throwing exception. I am using .Net Mail Address overloaded constructor. MSDN says it will throw FormatException when address contains non-ASCII characters. But I am unable to reproduce exception.

var addr = new System.Net.Mail.MailAddress("ñ@c.com","test", Encoding.UTF8);

If this is recognized email address then I am searching for a character which will throw exception to unit test.

2

There are 2 answers

1
Daniel Lemke On

The documentation seems to be outdated. Unicode characters are supported since .NET 4.0 in the mail addresses, see the following blog article: http://blogs.msdn.com/b/ncl/archive/2009/08/06/what-s-new-in-system-net-mail.aspx

0
Luaan On

The source code is quite clear on the subject - there is no check for unicode characters.

This means that the documentation is outdated - for quite a while, unicode domain names have been supported. The only thing remaining of the old checks is only applied when the SMTP server you're using to send the e-mail doesn't support Email Address Internationalization.

In other words, don't validate unicode content in e-mail addresses as an error - it's not invalid.