Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

.Net MailAddress fails on "ñ" in email address

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

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

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

like image 990
Dugan Avatar asked Dec 16 '10 05:12

Dugan


People also ask

Is .NET a valid email address?

Based on the result above, the regex has validated emails with .com, . net, and . gov as valid addresses.

Why do I keep getting invalid email address?

Invalid email addresses belong to inactive recipients who don't engage with your content. The unengaged email addresses can be invalid for a few reasons: Invalid emails can have typos or misformatting that do not lead to a legitimate inbox.

Can you have brackets in an email address?

An email address also may have an associated display name for the recipient, which precedes the address specification, now surrounded by angled brackets, for example: John Smith <[email protected]>.


1 Answers

Yeah, interesting. According to Wikipedia: Email Address, it's strictly defined as being a subset of ASCII, so that is technically invalid.

So, it seems you just strictly can't send email to that address from .NET (using the System.Net.Mail classes, anyway).

like image 109
Noon Silk Avatar answered Oct 11 '22 19:10

Noon Silk