-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmailer.js
76 lines (69 loc) · 2.14 KB
/
mailer.js
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
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
const nodemailer = require("nodemailer")
const mailTransport = nodemailer.createTransport({
service: 'gmail',
auth: {
user: 'frozenmango747@gmail.com',
pass: process.env.GMAIL_PASS
}
});
async function sendEmail(mail){
console.info(`Sending email to ${mail.to}.`)
await new Promise((resolve, reject) => {
// verify connection configuration
mailTransport.verify(function (error, success) {
if (error) {
console.log(error);
reject(error);
} else {
//console.log("Server is ready to take our messages");
resolve(success);
}
});
});
await new Promise((resolve, reject) => {
// send mail
mailTransport.sendMail(mail, (err, info) => {
if (err) {
console.error(err);
reject(err);
} else {
//console.log(info);
resolve(info);
}
});
});
}
async function sendVerificationEmail(to, token){
const link = process.env.HOST + "/verify?id=" + token;
const mail = {
from: 'tango@frozenmango747.com',
to,
subject: 'Verify Your Email',
html: `please click this link to <a href="${link}">verify your email.</a>`
};
sendEmail(mail)
}
async function sendEmailChangeNotificationEmail(to, newEmail){
const mail = {
from: 'tango@frozenmango747.com',
to,
subject: 'Your Email Address Was Changed',
html: `This is to notify you that your email address has been changed to ${newEmail}. <br/> If this is a mistake, please let us know immediately.`
};
sendEmail(mail)
}
async function sendPasswordResetEmail(to, token){
const link = process.env.HOST + "/reset-password?id=" + token;
const mail = {
from: 'tango@frozenmango747.com',
to,
subject: 'Reset Your Password',
html: `please click this link to <a href="${link}">reset your password.</a>`
};
sendEmail(mail)
}
module.exports = {
sendVerificationEmail,
sendPasswordResetEmail,
sendEmailChangeNotificationEmail
}