Skip to content

Latest commit

 

History

History
100 lines (93 loc) · 3.93 KB

README.md

File metadata and controls

100 lines (93 loc) · 3.93 KB

License

mail43 is a free library for your server. If your website has a login and sign up form, is usefull to fave an email verification system for avoid spam users or just to have more trust from new users.
This library is garanteed up to a certain point, this means that any modification (possible being open source) will not be subject of technical support.

How to use it

Install
npm i express nodemailer mail43 --save

Inside your server.js
// Express
const express = require('express');
const app = express();

/* * * mail43 * */ const mail43 = require('mail43');

// declaring an email account const EMAIL_ACCOUNT = new mail43.account(app, 'YOURDOMAIN.COM', { host: 'smtp.example.com', port: 465, use_tls: true, username: 'no-reply@example.com', password: 'Your email password' });

// verifying an user const verification = EMAIL_ACCOUNT.verify('example@gmail.com', { subject: 'Email verification test', body: 'Hello world!<br>Press this button: {button}<br>Or if it doesn't work, use this link {link}' }, 'YOUR_REDIRECT_URL', feed)

// handling feeds function feed(callback_type, data){ if(callback_type === 'error') throw new Error(data); else if(callback_type === 'sended') console.log("Sended email verification (UUID: %s", data); else if(callback_type === 'verified' && data === verification) console.log("User verified the Email Account, UUID: %s", data); }

// Starting server app.listen(3000);

Understanging the example (STEP by STEP)

First, you have to install Express, Nodemailer and Mail43
  1. npm i express nodemailer mail43 --save

Open your JavaScript server main file and import packages
  1. const express = require('express')
  2. const mail43 = require('mail43')

Create your express server
  1. const app = express();

Declare your email account (example: name@posteal.com)
const EMAIL_ACCOUNT = new mail43.account(app, 'YOURDOMAIN.COM', {
    host: 'smtp.example.com',
    port: 465,
    use_tls: true,
    username: 'no-reply@example.com',
    password: 'Your email password'
  });
How you can see, the mail43.account constructor, requires 3 parameters, the first one is your express app, then your domain, use for links and CTA in the email, and the last is your email authentication info

After a user complete the sign up form, send him the verification
const verification = EMAIL_ACCOUNT.verify('example@gmail.com', {
    subject: 'Email verification test',
    body: 'Hello world!<br>Press this button: {button}<br>Or if it doesn't work, use this link {link}'
}, 'YOUR_REDIRECT_URL', feed);
This function returnes the verification UUID that you will use for comparison
{button} will be replaced with a nice style button written in HTML and CSS, and {link} with the link


Create the function "feed" that will hand the requests
function feed(callback_type, data){
     if(callback_type === 'error') throw new Error(data);
     else if(callback_type === 'sended') console.log("Sended email verification (UUID: %s", data);
     else if(callback_type === 'verified' && data === verification) console.log("User verified the Email Account, UUID: %s", data);
}
the callback function (in this case it's "feed") accept 2 parameters, the callback_type and the data.
callback_type can be "error", "sended" or "verified".


  • "error" means that there is an error while sending the message, it returned the Error String (in the "data" variable)
  • "sended" means that the email il succesfully sended, it returns the UUID (in the "data" variable)
  • "verified" means that the user has verified his email, it returns the UUID (in the "data" variable)