Created
October 12, 2019 04:58
-
-
Save luandevpro/879a0b3cc80b51eba48895e914453a66 to your computer and use it in GitHub Desktop.
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
import * as speakeasy from 'speakeasy'; | |
import nodemailer from 'nodemailer'; | |
export default async function handle(req, res) { | |
const result = JSON.parse(req.body); | |
const secret = await speakeasy.generateSecret({ length: 20 }); | |
const token = await speakeasy.totp({ | |
secret: secret.base32, | |
encoding: 'base32', | |
}); | |
const mailOptions = { | |
from: "'Mr. Fox 🦊' <user@website.com>", // sender address | |
to: result.email, // list of receivers | |
subject: 'Hello World', // Subject line | |
text: `Hello World? `, // plain text body | |
html: `<p>Token : ${token} , ${secret.base32}</p>`, // html body | |
}; | |
const transporter = nodemailer.createTransport({ | |
service: 'gmail', | |
auth: { | |
user: 'clgtccgt9@gmail.com', | |
pass: 'luan12345', | |
}, | |
}); | |
transporter.sendMail(mailOptions, (error, info) => { | |
if (error) { | |
return console.log(error); | |
} | |
console.log('Message sent: %s', info.messageId); | |
res.json({ secret: secret.base32 }); | |
}); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment