Send email verification mail and use custom domain to send emails using Node.js

 const jwt = require(‘jsonwebtoken’);
const nodemailer = require(“nodemailer”);
var date = new Date();
var mail = {
“created”: date.toString()
const token_mail_verification = jwt.sign(mail, config.jwt_secret_mail, { expiresIn: ‘1d’ });

var url = config.baseUrl + “verify?id=” + token_mail_verification;
let transporter = nodemailer.createTransport({
name: “",
host: “”,
port: 323,
secure: false, // use SSL
auth: {
user: “”, // username for your mail server
pass: “Password”, // password
});// send mail with defined transport object
let info = await transporter.sendMail({
from: ‘“NAME” <>’, // sender address
to:, // list of receivers seperated by comma
subject: “Account Verification”, // Subject line
html: "Hello,<br> Please Click on the link to verify your email.<br><a href="+url+">Click here to verify</a>"
}, (error, info) => {
if (error) {
console.log(‘Message sent successfully!’);
app.get(‘/verify’, function(req, res) {
token =;
if (token) {
try {
jwt.verify(token, config.jwt_secret_mail, (e, decoded) => {
if (e) {
return res.sendStatus(403)
} else {
id =;
//Update your database here with whatever the verification flag you are using}});
} catch (err) {
return res.sendStatus(403)
} else {
return res.sendStatus(403)




Founder at

Love podcasts or audiobooks? Learn on the go with our new app.

Recommended from Medium

Cheat Sheet for JS methods to work with DOM, part 1

Creating Media with Anime.js — 001

The Beginner’s Guide to React Redux

Custom Events in JavaScript

Basic HTTP Server Using NodeJS From Scratch

Creating a Landing Page Using TUK Components

Dynamic Data and Maps — ReactJS Tutorial — Leaflet and Cluster Groups #3

Get the Medium app

A button that says 'Download on the App Store', and if clicked it will lead you to the iOS App store
A button that says 'Get it on, Google Play', and if clicked it will lead you to the Google Play store
Sarthak Singhal

Sarthak Singhal

Founder at

More from Medium

Nextjs — introduction to deployment🚀: Nextjs video tutorial series 📺

Nuxt3 complex solutions: database integration

How to use next/image with cloud providers

How to use multiple node js versions