What methods can be used to validate email accounts at the code level?
Summary
What email marketers say16Marketer opinions
Marketer from Email Geeks mentions you could also pay a third-party validation service, whilst it will catch a lot of typos, they are no substitution for confirming the address when you get it.
Marketer from Email Geeks shares that if you're on a budget and really don't mind loosing some valid addresses, you could remove any address with numbers or more than one full stop/period.
Email marketer from GitHub answers a question about email validation by introducing the is_email() function, a PHP email validator. The validator checks syntax, DNS records, and performs some level of spoof checking. It provides different levels of validation and can be customized for specific requirements.
Email marketer from Reddit warns against SMTP validation (HELO/MAIL FROM/RCPT TO) due to rate limiting and greylisting. Modern mail servers often block or delay connections from unknown sources to prevent spam, making this method unreliable.
Email marketer from Reddit suggests using an external email verification service, like ZeroBounce or NeverBounce, for best results. These services check the syntax, domain, and mailbox existence, resulting in more accurate validation.
Marketer from Email Geeks explains that regex will not cover all cases of validating email addresses. Some regexes exist for cleaning up .con vs .com, hotmal vs hotmail etc. There’s APIs you can use of course to bulk validate a suspicious list too.
Marketer from Email Geeks says that validating syntax won't do anything for you, as those are valid addresses. There are scripts that will make a connection to the MX but abort the connection after RCPT TO, the idea being that if RCPT TO doesn't error that the address exists. But then ESPs have implemented things to prevent this kind of address scraping. The best thing to do is just send an opt-in.
Marketer from Email Geeks suggests finding patterns such as you have above and using a combination of regexes. Maybe you could look at people who have email addresses that are very similar to others in your database? If you see five like the above, almost certainly spammy. So it might be the relationship between emails in the database rather than a regex.
Marketer from Email Geeks suggests putting the removed emails into a reconfirmation campaign and slowly sending to them.
Email marketer from Stack Overflow shares that, in addition to validating syntax, check for common disposable email domains. Also check if the domain has a valid MX record, as well as looking out for common typo domains like gnail.com
Marketer from Email Geeks suggests matching on 5 or more full stops to clean up suspicious emails. Check that against known good emails though.
Marketer from Email Geeks shares that Confirmed Opt-In is the best way to keep a list free of bogus or mistyped addresses.
Marketer from Email Geeks suggests that if you have any data about the performance of these recipients, that’s probably a far better indicator of being valid or not. No opens in 12 months? Ditch.
Email marketer from Stack Overflow shares using `filter_var($email, FILTER_VALIDATE_EMAIL)` as the standard method, noting that full compliance with RFC 822 is impractical. Also explains that MX record lookup is a good secondary validation step, but explains a full SMTP VRFY is unreliable.
Email marketer from Stack Overflow explains that you should filter the input with FILTER_VALIDATE_EMAIL. Then perform a DNS lookup for the domain's MX record. Finally, attempt to open a socket to the mail server. This confirms both the format and existence of the domain.
Email marketer from Email Hippo explains that using a bulk email validation tool is highly recommended. The tool will provide information on bad domains, syntax errors, disposable emails, greylisting errors and deliverability.
What the experts say2Expert opinions
Expert from Word to the Wise explains maintaining good email hygiene by removing invalid email addresses from your contact list is essential for deliverability. Suggests methods like syntax checking, domain verification, and SMTP handshakes, but notes these are imperfect and confirmed opt-in is superior.
Expert from Spam Resource responds with the reminder that all email validators are imperfect. Sending a confirmation email and requesting the recipient to click on a link is the most reliable way to validate an email address. If bounces are high, use a list cleaning service that performs mailbox validation.
What the documentation says5Technical articles
Documentation from RFC Editor outlines the formal syntax for email addresses. It details the allowed characters, structure of the local part and domain, and the use of comments and folding whitespace. It's important for understanding the technical specifications behind email address validation.
Documentation from Python Docs answers a question about Email Address Verification by introducing the email-validator library, which incorporates domain name validation, address parsing, and DNS queries to confirm the structure and legitimacy of an email address.
Documentation from Microsoft Docs explains how to validate an email address using regular expressions in C#. The example code uses the `Regex` class to match the email address against a pattern. It checks for a valid prefix, @ symbol, and domain. Also discusses limitations of regex-based validation, recommending additional checks.
Documentation from Freshworks describes the steps involved in Javascript validation - including using Regex to validate email addresses. It also includes using try and catch to validate the email address.
Documentation from OWASP explains that proper input validation is crucial to prevent email injection attacks. It recommends using allow lists of permitted characters and escaping any special characters. Also suggests using a dedicated email sending library that handles proper encoding and prevents injection vulnerabilities.