Know if a mail exists or not in Node.js

0

I'm doing an API that receives a JSON with various information of people, inside those an email, I need to validate if the email has the correct format, if the domain is correct and if the correct one actually exists in that domain.

This is the code that I currently have and it tells me if the domain exists and if it is well written but I need to know if that email exists too!

HELP !!

const dns = require('dns');
function Validar_email(email){
  let domain = email.split('@')[1];  
      dns.resolve(domain, 'MX', function(err, addresses) {    
       if (err) {
          console.log("Error")
          console.log(err)    
      } else if (addresses && addresses.length > 0) {      
         console.log("Correcto")
      }
        })
      }
    
asked by java005 07.09.2018 в 18:34
source

1 answer

2

I tell you my work experience, with 2 solutions:

SOLUTION 1

To validate if an email exists, what I have done is send a confirmation email to the corresponding client, this confirmation has a period of time, so two things can happen:

  • If the customer confirms in the period of time : Updates the corresponding information in database.
  • If the client does not confirm : I delete all the records in relation to the client (Because there is no such email), it is worth mentioning that the deletion consists of a state flag which assigned it with value true (Deleted ).
  • SOLUTION 2

    However, messaging services exist (such as: SendGrid), which contains an integrated API, in which the following solution can be implemented:

  • Send an email from the host that provides the service (It should be mentioned that each email will be identified by a unique identifier).
  • Later, you can consult the API of the messaging service, and check the status of the mail (Among them you can be: Sending, Sent, received, read, among others more ...).
  • EYE: In both solutions you must send an email.

        
    answered by 07.09.2018 / 19:51
    source