Created
August 17, 2019 07:58
-
-
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.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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