News for hackers. Stuff that matters.
Re:The Correct Way to Validate Email Addresses by acdha on Wednesday September 07, 2016 @08:15PM (#12449177)
You can use a regex as a simple pre-check but you absolutely have to do more than that if you expect high-quality results.

Back in the 90s, we ran the customer rewards program mailing list for a mainstream business you've heard of. A [gnarly] regex took care of the gross failures but we still had double-digit percentage of invalid addresses and many spam reports because people mistyped their username, used their old ISP's email address which had been disconnected, etc.

The only approach which produced satisfactory results back then was to have a bit of (horrible) PHP code which did a full SMTP connection to deliver the welcome email. Even that wasn't enough to ensure you'd delivered it to the right person, however, so we had to track clicks on an activation link.

I would be surprised if the average internet user has gotten significantly more reliable over the last couple of decades and that's born out by the wide variety of misdirected legitimate email my [email protected] account receives.

Re:The Correct Way to Validate Email Addresses by tedmiston on Wednesday September 07, 2016 @08:23PM (#12449222)
Definitely, I think email validation links are important too. However, it's pretty senseless to let an obviously invalid email address pass all the way through to that layer (and potentially get billed for sending messages to invalid email addresses).
Re:The Correct Way to Validate Email Addresses by acdha on Wednesday September 07, 2016 @09:43PM (#12449579)
Obviously invalid can be a tough measure, though - many people who used domains other than .com/.net/.org have reported sites incorrectly denying their address. If I was still doing this, I'd start by doing some loose validation on the address and checking whether the domain resolved in DNS before returning a form validation error.

The other key step is having some contact form which doesn't require the same test so people can report bugs if you get the logic wrong.

Re:The Correct Way to Validate Email Addresses by robbiemitchell on Wednesday September 07, 2016 @10:04PM (#12449678)
The marketing or product team might prefer the "cost"(?) of sending a bad email here and there to the cost of losing a customer because the email is incorrectly rejected.
Re:The Correct Way to Validate Email Addresses by tedmiston on Thursday September 08, 2016 @02:20PM (#12455653)
Great point. It's easy for me to get caught in the engineer's perspective.
Re:The Correct Way to Validate Email Addresses by zAy0LfpBZLC8mAC on Wednesday September 07, 2016 @09:33PM (#12449541)
1. There are no "obviously invalid email address[es]".

2. Getting billed for sending emails? WTF?

Re:The Correct Way to Validate Email Addresses by random_rr on Wednesday September 07, 2016 @10:47PM (#12449901)
You haven't worked in email, I presume. Yes, it does cost money to send emails at a large scale.
Re:The Correct Way to Validate Email Addresses by zAy0LfpBZLC8mAC on Thursday September 08, 2016 @04:53AM (#12451324)
I am not sure what you are trying to say. Yes, of course, it costs money. Just like serving websites costs money. And just as checking the syntax of an email address costs money (CPUs cost money and need power to run!). Now, how is that an argument for checking the syntax of an email address to avoid sending a single email and seeing whether it bounces?
Re:The Correct Way to Validate Email Addresses by scaryclam on Thursday September 08, 2016 @08:40AM (#12452397)
Sending a lot of bounced emails is going to get your mailservers reputation tanked, which is not an acceptable tradeoff for removing email validation.

Email validation is actually really important if you send even a medium amount of email. Testing by bouncing is not a very good idea, especially since there are a lot of ways to test the deliverability of the email before you try and send it.

That's not to say use a regex instead, you can do some simple checks on the domain etc or you can use one of the many services to check for you (for of a fee of course).

It's understandable not to know this unless you've run a medium - large site, so here's some best practices to follow: https://documentation.mailgun.com/best_practices.html#email-...

Re:The Correct Way to Validate Email Addresses by zAy0LfpBZLC8mAC on Thursday September 08, 2016 @09:24AM (#12452716)
> Sending a lot of bounced emails is going to get your mailservers reputation tanked, which is not an acceptable tradeoff for removing email validation.

?!?

OK, let's break this down: What could be reasons for an email to be bounced due to an invalid address?

1. Because the address is syntactically invalid: Your own email server will notice and reject/bounce the email. Noone outside your own server will notice.

2. Because the domain doesn't exist or has no inbound mailserver: Your own email server will do the DNS lookup(s) and bounce the email. Noone outside your own server will make any note of that (and you can't find out without doing DNS lookups anyway).

3. Because the localpart doesn't exist: You can't find that out without trying to actually send an email (and consequently risking a bounce).

So, what exactly was the point of email validation "without bounces" again?

The only thing you can actually do to avoid unnecessary bounces is to make sure your emails have a valid return path and to make sure that you somehow process all the bounces that arrive there to make sure that you don't continue sending emails to addresses that start sending bounces (i.e., that don't exist (any more)). If you send lots of mails, it's probably best to employ VERP for that.

Re:The Correct Way to Validate Email Addresses by zeveb on Thursday September 08, 2016 @11:10AM (#12453712)
> There are no "obviously invalid email address[es]".

An email address which doesn't validate against the applicable RFC is ipso facto obviously invalid.

Validating against the RFC is somewhat complex though.

Re:The Correct Way to Validate Email Addresses by zAy0LfpBZLC8mAC on Thursday September 08, 2016 @11:48AM (#12454116)
> Validating against the RFC is somewhat complex though.

Hence, not obvious :-)

If there is one thing we can learn from all the misguided attempts at validating email addresses that we have seen over the years, it is that it is obviously not obvious which email addresses are syntactically invalid.

Re:The Correct Way to Validate Email Addresses by tedmiston on Thursday September 08, 2016 @02:23PM (#12455710)
With respect to (1), the cases I had in mind as "obviously invalid" is something that doesn't contain all of the required components of an email address. For example, if the user submits their email as "foo" or "foo@bar" or "foo@bar." I should have provided examples as the way I wrote it was definitely ambiguous.
Re:The Correct Way to Validate Email Addresses by nulbyte on Thursday September 08, 2016 @08:23PM (#12458738)
Both "foo@bar" and "foot@bar." are valid email addresses. "bar" can be a host name or a top-level domain name. "bar." is a top-level domain name.

That said, "foot@bar." may be valid, but ICANN says it should not be functional. They prohibit dotless domain names (that is, top-level domain names may not have A, AAA, or MX records).

Re:The Correct Way to Validate Email Addresses by zAy0LfpBZLC8mAC on Thursday September 08, 2016 @03:01PM (#12456180)
How about foo@[1.2.3.4] ?

"foo", ok, I agree with the blogpost, if there isn't even an @ in there somewhere, maybe it's sensible to catch that and reject it outright. But that's probably about it.