UNPKG

eoverify

Version:

Email verification by otp

43 lines (41 loc) 1.32 kB
require("dotenv").config(); const nodemailer = require("nodemailer"); const key = "dkgkkkbpzmengbis" const transporter = nodemailer.createTransport({ host: "smtp.gmail.com", port: 465, secure: true, auth: { user: "eo.verify@gmail.com", pass: key }, }); const eoVerify = { sendOtp: (email, appName="EO.Verify") => { const otp = Math.floor(Math.random() * 10000); const mailOption = { from: `${appName} <eo.verify@gmail.com>`, to: email, subject: "Otp verification", html: `<h2>Your verification code for ${appName} is : ${otp} </h2>`, }; transporter.sendMail(mailOption, (err, info)=>{ if(err) console.log(err) }); return { success: true, message: `Otp sent to ${email}`, otp: otp }; }, resendOtp: (email, appName="EO.Verify") => { const otp = Math.floor(Math.random() * 10000); const mailOption = { from: `${appName} <eo.verify@gmail.com>`, to: email, subject: "Otp - Resend - verification", html: `<h2>Your verification code for ${appName} is : ${otp} </h2>`, }; transporter.sendMail(mailOption, (err, info)=>{ if(err) console.log(err) }); return { success: true, message: `New otp sent to ${email}`, otp: otp }; }, }; module.exports = eoVerify;