1

I am in charge of developing an application that needs to upload a lot of user data in a batch way. One of the users' data is an email address and we need to make sure that this email address really exists so that we can send a welcome message.

So, how could I check if an email address really exists?

edddd
  • 433
  • 3
  • 17
Andrez Segovia
  • 126
  • 2
  • 9
  • 2
    What specifically do you mean by "really exist"? Are you checking if it's already in your data? Are you checking if it's a valid format for an email address? Something else? – David Mar 13 '20 at 16:58
  • 4
    Similar to question (while the ans is for PHP - you can adapt for node: https://stackoverflow.com/questions/565504/how-to-check-if-an-email-address-exists-without-sending-an-email – alpharomeo Mar 13 '20 at 16:59
  • 2
    You can check if it is a valid email pattern with regular expressions (google regEx) And the only way to find out if this email address really exists and belongs to a user (at least as far as I know), is to send an email to it and see if your mailserver throws an error or not. – Andre Mar 13 '20 at 17:04
  • Start the user's account in a pending state until someone clicks on an encoded link you send them by email. But you should then also support "Please re-send" and "Correct my email address" features. Or, much better, you could just implement federated sign-on to your app via social providers such as FB and Google. – jarmod Mar 13 '20 at 17:15
  • The only way to know if it's a legitimate email address that the user singing up actually has access to is to send them an email with a special link with a dynamic code in the link in it and ask them to click on that link to verify the email address. This also prevents typos in their email address that are still legitimate email addresses, but not the intended email address for the user signing up. If you don't verify, then people can spam real users by putting their email into the service. You SHOULD verify the email address in this way. – jfriend00 Mar 13 '20 at 17:18
  • @David I'd like to check whether the email address is right and has a mailbox. – Andrez Segovia Mar 13 '20 at 18:11

3 Answers3

1

You can check the format of an email address for RFC5322 compliance using npm email-validator:

const validator = require('email-validator')
...
if (validator.validate('test@email.com')) {
   /* email format is correct */
}

But you're asking if there's a general and reliable way to ask the intertoobz if there's a real mailbox behind any given email address.

The answer is no, except by sending a message to the mailbox and asking the recipient to respond. There are unreliable ways to check for a mailbox's existence, but many mail transfer agents do not implement them. Why not? Spam.

Commercial mail services (Constant Contact, MailChimp, SendGrid) offer features to send a message to a mailbox requesting permission to give it a subscription to an email service. The person behind the mailbox usually responds by clicking a hyperlink. The hyperlink contains a nonce -- a hard-to-guess random value -- that identifies the mailbox. Only after the URL click can you be sure the address exists. Sometimes end-users are asked to "confirm your email address" using this technique.

Those same services are good about tracking email bounces and failures, so they can have a temporary idea about what mailboxes don't exist. They go to a lot of trouble to avoid sending junk, because the big email providers (gmail, outlook.com, comcast, charter, and the rest) routinely blacklist servers sending email, to lower their spam load. When you use a service, you're paying for a lot of network-engineering work to prevent blacklisting.

You can implement a similar "permission to subscribe" service in your own application, but explaining how to do that is beyond the scope of a StackOverflow answer. Keeping it from being blacklisted? Probably very difficult unless your volume is very low.

See this for more discussion.

Can I check if an email address exists using .net?

I've used SendGrid.com 's free service tier, and it works well. I've also used MailChimp successfully.

Community
  • 1
  • 1
O. Jones
  • 103,626
  • 17
  • 118
  • 172
0

You can use a service like EmailChecker (I just did a quick google search) to check if the email really exists.

To use the API you need to pay for premium but you can see how it works here: https://email-checker.net

Evan Hennessy
  • 197
  • 1
  • 6
0

Validating that an email address is a legal (e.g., mailable) format is one thing, but it doesn't tell you that there's a mailbox at that address. The only way to know if an email address "exists" is to mail something to it. If it [eventually] bounces, you can be pretty sure that it doesn't exist. Otherwise, all you know is that somebody's SMTP server accepted the message.

See https://haacked.com/archive/2007/08/21/i-knew-how-to-validate-an-email-address-until-i.aspx/

and this:

How to check if an email address exists without sending an email?

Nicholas Carey
  • 71,308
  • 16
  • 93
  • 135