0

I'm working on our email validation, and I know that the constructor for MailAddress accepts invalid addresses as input without throwing an exception, an example would be an address containing two atoms like so add..ress@domain.com. That particular example is sorta documented in the code for the mailaddress, http://referencesource.microsoft.com/#system/net/System/Net/mail/DotAtomReader.cs.

Are there other kinds of invalid input that the MailAddress constructor is known to accept?

Icemanind
  • 47,519
  • 50
  • 171
  • 296
jmoreno
  • 12,752
  • 4
  • 60
  • 91
  • This question is possibly duplicated [here](https://stackoverflow.com/questions/25938981/system-net-mailmessage-allows-some-invalid-email-address-formats) and it might answer your question. For validation though, it might be best for you to use RegEx to validate it. Try looking [here](http://emailregex.com/) – Icemanind Dec 28 '17 at 14:23
  • @Icemanind: that is certainly related to my question, but it seems more a rant than an actual question. Not looking to replace what we currently do with a regex, neither a small one that gets most things right, nor the 8k monster that gets everything right. – jmoreno Dec 28 '17 at 14:31
  • More related to your question, the [docs for MailAddress](https://msdn.microsoft.com/en-us/library/system.net.mail.mailaddress(v=vs.110).aspx) do specifically spell out all the formats that the constructor accepts, including the `Consecutive and trailing dots in user names`. Scroll down to the remarks section. – Icemanind Dec 28 '17 at 14:40
  • The reason why these quirks exist is that "other people let these things happen", which in turn means that someone *may* actually be using an email address with multiple consecutive dots (in the local part, at least, because that's not held to conformance by DNS requirements). So you can be "pure" and only accept email addresses per the RFC or you can accept that that ship has already sailed and accept the (slightly) laxer validation that `MailAddress` provides. At the end of the day, only actually sending an email and demanding proof of receipt proves that an email address was valid recently – Damien_The_Unbeliever Dec 28 '17 at 14:40

0 Answers0