简体   繁体   中英

Unicode character in email not throwing exception

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.

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

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.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM