.Net MailAddress not working on "-" in email address

The following code throws an exception: "An invalid character was found in the mail header:" - ". ::

string email = @c.com"; MailAddress to = new MailAddress(email); 

The actual address I'm running on is a valid address, but the MailAddress class throws an error whenever I try to use it.

+8
c # localization
source share
1 answer

Yes interesting. According to Wikipedia: Email address , it is strictly defined as a subset of ASCII, so this is technically invalid.

So it looks like you just can't send emails to this address from .NET (using the System.Net.Mail classes, anyway).

+5
source share

Source: https://habr.com/ru/post/650192/


All Articles