-
Notifications
You must be signed in to change notification settings - Fork 3.6k
Expand file tree
/
Copy pathemailer.js
More file actions
39 lines (35 loc) · 1.22 KB
/
emailer.js
File metadata and controls
39 lines (35 loc) · 1.22 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
require('dotenv').config()
const nodemailer = require("nodemailer");
var jwt = require('jsonwebtoken');
var transporter = nodemailer.createTransport({
host: "live.smtp.mailtrap.io",
port: 587,
auth: {
user: "api",
pass: process.env.MAIL_TRAP_API_TOKEN
}
});
const sendEmail = async (request) => {
// 2.2 User doesn't exists
// 1. Send OTP to end user
const dataToEncrypt = {
email: "arulvinayakmenon@gmail.com"
}
// const basePath = "https://long-jade-sheep.cyclic.cloud/verify"
const basePath = "http://localhost:3000"
const token = jwt.sign(dataToEncrypt, "secretKey", { algorithm: 'HS256' });
const mailSendingStartTime = new Date()
const info = await transporter.sendMail({
from: '"Welcome from Halo 👻" no-reply@haloeffect.in', // sender address
to: "arveymenon@gmail.com", // list of receivers
subject: "Verfication Link ✔", // Subject line
text: "Test mailer. Yo Bro!", // plain text body
html: `<a href="${basePath}/user/verify/${token}">Verify</a>`,
})
.then((r)=>{})
.catch(e=>console.error("ERR",e));
console.log(new Date() - mailSendingStartTime)
return;
//
}
module.exports = { sendEmail }