4 ms·
Email Validation Logic is Wrong (2021)
- johncessna 4y ago15. If you want to validate an email address send them a validation email.
- chadlavi 4y agoThis is the way. Or if you REALLY want a regex for an input, /[^\s]+@[^\s]+/ seems as sure as you can get without excluding a valid address somewhere. At least one non-whitespace character followed by an @ followed by at least one non-whitespace character. Any more specific than that and it's dicey. But also just send an email instead if you need to validate the email address.
- deepspace 4y agoHa, that is how I have always done it. Verify that there is at least one @ in the "address", and then send a verification email to it. The software that is most qualified to validate a user's email address, is the user's email server software. Why would I want to duplicate everything it does?
- coldcache 4y agoSee also https://beesbuzz.biz/code/439-Falsehoods-programmers-believe-about-email https://beesbuzz.biz/code/439-Falsehoods-programmers-believe...
- CodesInChaos 4y agoWhile the RFC allows a lot of weird email address edgecases, I see little reason to allow most of these when a user signs up to my service. How many legitimate users will use quoted strings, dotless domains or even IP addresses?
- roflyear 4y agoWell, why block them unless you have a good reason to?
- mgkimsal 4y agoit implies support, and may place more burden on testing. if you test with XYZ only, but also allow ABC... then ABC stops working... you'll have pissed off customers.
- c22 4y agoWhereas if you block ABC outright you'll just have pissed off people who aren't customers!
- mgkimsal 4y agoSure, but that's a different story. You might piss them off and lose customers. You may also be knowingly increasing your support costs. For the average company trying to navigate these sorts of decisions, supporting users with emails like "a$123@1-2-3.12397.museum" probably isn't high on their list of priorities, regardless of whether it's "valid" or not.
- roflyear 4y agoYeah not really talking about those addresses tho. Plenty of sites reject stuff like hi+whatever@whatever.com which is not super uncommon...
- jcranmer 4y agoThe basic rule of thumb I use this: are you implementing email at the MTA level (needing to build/parse RFC 5321 commands or RFC 5322 blobs directly), or are you using email closer to a "universal internet ID" purpose (i.e., application perspective)? If you are in the former category, then yes, follow the spec to the letter. If you're in the latter, then screw the precise guidelines of the spec and reject emails that are very unlikely to be valid: no quoted localparts, no IP address literals. In addition, go ahead and say that email is case-insensitive (more precisely, case-preserving).
- JamesCoyne 4y agomirror https://web.archive.org/web/20221217225311/https://www.netmeister.org/blog/email.html https://web.archive.org/web/20221217225311/https://www.netme...
- advisedwang 4y agoDown for me; https://archive.ph/ucEpi https://archive.ph/ucEpi
- ok_dad 4y agoI have a TLD that is 4 letters and non-standard to the usual .com, .net, .org, or even .io addresses you see everyday. I regret it so much, because I still found places where 4-letter TLDs are flagged as invalid. Additionlly, sub-domains are often "invalid", and I use addresses like `site@subdomain.domain.weird` to keep track of who sells my information. I had to buy a .com domain to have a backup for those sites that invalidate my normal addresses. Nowdays I have started to use Fastmail's "masked email" feature for a lot of sites (so I just get `random.words1234@fastmail.com`), but that requires more config than just my usual scheme.
- Tomte 4y agoSingle letter local part used to be a big problem, and still sometimes is, but it's getting better. Hey, Microsoft has stopped declaring my primary mail address invalid a few years ago.
- iinnPP 4y agoI have had a similar problem with the 4 letter extension causing issues. What is really annoying is the sites that allow the signup with the 4 letters but then proceed to fail at every other opportunity up to and including opt out(GAP). I spent an hour with them over the phone before anyone even understood what I was saying. I am also now using Fastmail addresses for anything I don't have some trust for and isn't a problem if lost. I no longer use my domain for things outside of this because it seems like an obvious step to simply link an unknown domain together, even if a laughable amount of companies don't.
- jedberg 4y agoI used to work at Sendmail, and the people who literally wrote Sendmail, which had to understand every possible valid email, would always repeat this mantra: There is exactly one way to validate an email address, and that is to send it an email. No matter what regex you use, you will be wrong. Sure, use the 800 line regex to do a pre-validation and ask the user "are you sure this is correct?" if it fails, but let them use it anyway if they click yes, because it might just be valid. Then send it an email and if it bounces or they don't click the verification link, move on and delete it.
- ComputerGuru 4y agoYeah, but sending emails that bounce via SES or any hosted service hurts your business because it lowers your trust rating. You are expected to filter crap from reaching their servers. "But @jedberg told me the only way I could know that foo!fu*k_your-momma"<>"123:hello@fuckyou.com is an invalid email was to send to it" won't fly.
- jedberg 4y agoObviously you have to take other precautions and not just blindly try to validate any email you get. But my point was you shouldn't reject an email only because it fails regex validation. Also, those services don't ding you if you get a single bounce from a new email. They only start penalizing you if you repeatedly send to the same email and it bounces. You could always put checks in place to store previously failed email addresses. And if your business is generating a bunch of take signups, it sounds like you need to put some rate limits on your sign up page. And of course that's not deliverable, you can't use a : outside of a quoted part. :) But that is actually a perfect example of why you can't use a regex. Maybe they modified their mail server to accept it.
- hooverd 4y agoYea, SES has a suppression list you manage that by default doesn't send. You can rig up an event bus to automatically add bounces to it.
- ComputerGuru 4y agoMy problem with all these is simple: unlike dealing with people's names which, for the most part, they did not choose and have legitimate cultural reasons for the presence of special characters therein, it's not my problem if someone wants to register on my site with an (RFC-compliant!) email like @1st.relay,@2nd.relay:user@final.domain or a quoted email like (following payload is unquoted, quotes you see are part of the email address) "<>"@netmeister.org I am going to put a (sane and reasonable) maximum length for email addresses on my postgres db column so it's not stored in TOAST; I don't care if you're technically allowed 256 bytes before the @ sign: I'm not wasting space in my database so you can feel special. I do validate that the domain not only resolves but that it also has a valid MX record because this benefits ~100% of my users and protects them from their typos. It's not my problem if you want to register for my service before you set up your nameservers - its yours. etc, etc, etc. It's a fun thought experiment but there's no way in hell I'm going to advise any company to actually allow any of these and open themselves up to a can of worms. A more sane list of rules would be things like "make sure you support - in the prefix or the domain" and others of its ilk. Also, I came across an email address that was created automatically from Active Directory to Azure with the apostrophe preserved (think "Sean O'Henry" turned into "sean.o'henry@example.com" and it blew my mind when that "just worked" in testing. These would be helpful rules because you'll actually encounter them in the real-world and not supporting them will genuinely inconvenience real people and not someone's PhD research.
- citrin_ru 4y ago> I do validate that the domain not only resolves but that it also has a valid MX record because this benefits ~100% of my users and protects them from their typos. It's not my problem if you want to register for my service before you set up your nameservers - its yours. In absence of an MX record MTA will use an A record and a small but non-zero fraction of domains really has an A record pointing to a mail server.
- quags 4y agoHaving no mx record and the domain A record pointing to a mail server is valid and is a small edge case. If one were to validate mx records for an a to spam measure using this the false positive rate would be extremely low. Really anyone not having an mx record and using the A record of the root domain I’d love to hear what you are doing. I didn’t even know this was a thing until a two years ago in a career of 20 plus years.
- Thaxll 4y agoYeah RFC says something reality is very different, allowing multiple @ in 2023 is just stupid and not how emails work, as a matter of fact gmail does not allows it.
- HWR_14 4y agoWhat's the case not to just attempt to send the email with a link? That's how I know if an email is correct or not.
- icedchai 4y agoSome email services (like Amazon SES) track your "bounce rate" and ding you on it. When you're sending too many bounces, you can have operational issues. They'll shut you off.
- HWR_14 4y agoSure, given a magic oracle avoiding the bounces is good. But what percentage of bad emails can be detected before testing? Especially at the level that a regular expression can detect?
- jp191919 4y agoI can't stand websites that say my email is invalid because it has a "+" in it. If the site doesn't allow it I usually take my business elsewhere.
- davchana 4y agoThe more bad thing is, where they take the one with + at sign up, but their login page throws error on email with + sign. Indian Pension Fund, a government website does it. You can signup with example+enps@anything.com but can't login. If you try to login with example@any, it will say email not found. They only way around is either go in person & submit a paper form; or signup from scratch with a new email.
- avgcorrection 4y agoWhy are email addresses so complex? Who needs all that junk?
- tgv 4y agoHistory.
- avgcorrection 4y agoIn this moment I am enlightened.
- icedchai 4y agoIt's all legacy, tech debt from the early Internet days (and before.) My first email address was through a UUCP feed, back in 1991 or so. We used bang paths. My email was something like uunet!host2!host1!username.
- velcrovan 4y agoWhen validating email addresses in my Atom feed generation library, I use a "common-sense subset" of RFC 5322 [1]. If that email address validation is "wrong" anywhere in the sense of conflicting with real-world usage, it's probably mostly in not allowing UTF-8 characters in the local or domain parts. I'm guessing that for that I'll need to dig into RFC 6531 and 5890. [1]: https://docs.racket-lang.org/splitflap/mod-constructs.html#%28def._%28%28lib._splitflap%2Fconstructs..rkt%29._email-address~3f%29%29 https://docs.racket-lang.org/splitflap/mod-constructs.html#%...
- paxys 4y agoThe article comes off as a "gotcha! Your service is broken!!" but ask any developer or product owner about this and they will simply say that they don't care about the 0.00001% of users signing up with such emails.
- flexiflex 4y agoI often find that my single character local address fails, and I need to add a plus something. e.g. x@familyname.com is rejected, but x+whydidyourejectthis@familyname.com works