How to check if an email really exists?

28

I made an email field for the user to register, and now I need a system that checks to see if this email exists.

I need when the user enters their email a system to verify that it exists, if it even has that email. For example, the user types: usuá[email protected] , it will appear next to: "valid email" or "invalid email".

I have already researched email validation system but no concrete results appear. Can anyone help me?

    
asked by anonymous 05.03.2014 / 01:05

5 answers

44

Without user interaction you will only be able to verify that the email is valid (well-formed) or not.

Although the SMTP protocol allows for checking accounts, multiple mail servers no longer offer this function because of abuse of this function by spammers .

To check if the email even exists, it is necessary to create one more step in your account. When the user registers, register their status as "pending" or something, and send a confirmation email to the address given. The email should contain a unique link from that user, such as an informed email hash + some arbitrary value like salt .

When the user accesses the link (which points to your system), you check the last hash, and update the status to "registered."

    
05.03.2014 / 03:26
12

It is impossible to do a final validation of an email address because many destination SMTP servers accept messages even for addresses that do not exist, and perhaps only then return a message to a sender stating that the email is not valid.

However, what you can do is to simulate sending a message to the given e-mail address and see if the destination SMTP server would accept the recipient.

To do this you need to consult the DNS to obtain the MX record of the informed domain so that you know what the server is or the servers that would receive the message for that domain. It can give 1 server, several or even none. In the latter case the server to be used must be that of the domain A record.

It connects to port 25 of each of the servers. If one of them already refuses the recipient, you already know that it is invalid. If one of them accepts, you already know that it is valid. If no server accepts the connection or gives an error with code 4XX, you can not tell if it is valid, as it is a situation that may be temporary.

Implementing this algorithm properly is a little painstaking. However I myself have developed a class of PHP for email validation which already implements these steps all and has been improved since 1999.

In addition, the class also allows you to define a list of domains that you will never want to accept, such as temporary e-mail.

    
05.03.2014 / 07:11
9

It is quite complex because it involves several techniques. The most common technique is email with account validation link. It helps a lot but it is not enough because email often falls in the spam box or sometimes it is not sent or even when it is valid, the user does not bother to click on the validation link.

Another technique is to create a listen on the response mail server. Example, send a confirmation email whose reply email will be to a special email where the pop server is waiting for a response. Usually returns "undeliverable mail" message when the destination server refuses an account even if it has a setting to receive the "trash emails". The most popular and easy to implement filter is procmail , under Linux systems.

But be careful when marking an invalid email permanently because a non-existent email may occur later. Example:

[email protected] probably does not exist. Assuming validation is done today, it will return as invalid. But if tomorrow someone will create exactly the same account? So, never permanently mark an email as invalid.

    
18.07.2014 / 08:44
6

I think you could do the following: When anyone includes the email and click send, your system sends him a message that he enters the email and makes the confirmation. Give your system the confirmation and register. If it does not confirm, your system does not register.

    
16.05.2015 / 18:25
0

You can send a message with an email validation link to the e-mail address, as soon as the user is redirected to your system and the email is given as valid.

There are other services that do email verification, follow the link of one of these services more famous.

link

    
21.06.2016 / 23:25