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.
Install
npm i express nodemailer mail43 --save
Inside your server.js
// Express const express = require('express'); const app = express();First, you have to install Express, Nodemailer and Mail43/* * * 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);
- npm i express nodemailer mail43 --save
Open your JavaScript server main file and import packages
const express = require('express')
const mail43 = require('mail43')
Create your express server
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)