email-verification-code

Send a Verification Code to Confirm the User Email's.

Usage no npm install needed!

<script type="module">
  import emailVerificationCode from 'https://cdn.skypack.dev/email-verification-code';
</script>

README

Email Verification Code

With this package, you are able to send email verification codes and confirm them with using only 2 functions!

Installation

This is a Node.js module available through the npm registry.

Installation is done using the npm install command:

npm install email-verification-code --save

Usage

const { sendCode, verifyCode } = require("email-verification-code");

// Send the code to the User Email.

const data = {
   smtpInfo: {
    host: '0.0.0.0',         
    port: 587,               
    user: 'test@example.com', 
    pass: 23454,      
  },
  company: {
    name: 'FahDev.',      
    email: 'FahDev@gmail.com', 
  },
  mailInfo: {
    emailReceiver: 'FahDev1@gmail.com',
    subject: 'Code Confirmation',     
    text(code) {
      return `The Confirmation Code is: ${code}`;
    },
    html(code) {
      return `<p>The Confirmation Code is: ${code}</p>`
    }
  },
}

sendCode(data);

// To verify the code validity

const response = verifyCode("example@email.com", 3429921)

console.log(response)

smtpInfo

Option Type Default Description Required
host String null SMTP HOST, required to Connect to Your SMTP & Send the mail True
port Number 587 SMTP PORT, required to Connect to Your SMTP & Send the mail True
user String null SMTP User, required to Connect to Your SMTP & Send the mail True
pass String null SMTP Password, required to Connect to Your SMTP & Send the mail True

company

Option Type Default Description Required
name String null Your company Name, sent in the FROM tag false, One of the two is Required.
email String null Your company email, sent in the from tag false, One of the two is Required.

mailInfo

Option Type Default Description Required
emailReceiver String null User or Receiver Email True
subject String null The mail Subject False
text Function '' The mail content. NB: This function must have only one parameter which corresponds to the Code False, One of the two is Required.
html Function '' The mail content. NB: This function must have only one parameter which corresponds to the Code False, One of the two is Required.

How it Work!

The script generates a 6-digit code with 1 hour validity and saves it locally (For security reasons, please call the backend functions) and then sends an email with the message you had inserted previously.

To check the code, all you need to do is have the email address and the code. The script will look for the code in the local database, compare it, delete it if the code is correct, and give you a response to do so.

License

MIT