Skip to content

Instantly share code, notes, and snippets.

@meetAhmed
Created August 17, 2019 07:58
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save meetAhmed/02f0cad96f98f9642e8aaf000e0f4fe9 to your computer and use it in GitHub Desktop.
Save meetAhmed/02f0cad96f98f9642e8aaf000e0f4fe9 to your computer and use it in GitHub Desktop.
Code for sending the verification emails in node js using the nodemailer and uuid library. This script exports the sendVerificationEmail method that takes two parameters email address and callback for the response to the calling agent.
var nodemailer = require('nodemailer');
const uuid = require('uuid');
var transporter = nodemailer.createTransport({
service : 'gmail',
auth : {
user : '',
pass : ''
}
});
function sendVerificationEmail(emailAddress,callback){
const uuidv1 = require('uuid/v1');
var v = uuidv1();
var arr = v.split("-");
var mailOptions = {
from : '',
to : emailAddress,
subject : 'Company Name - Email Verification',
text : 'Please verify your account using this code ' + arr[0]
};
transporter.sendMail(mailOptions, function(error, info){
if (error) {
console.log(error);
return callback(true);
} else {
console.log(info);
return callback(false,arr[0]);
}
});
}
module.exports = {sendVerificationEmail};
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment