-
Notifications
You must be signed in to change notification settings - Fork 4
/
Copy pathmailer.js
41 lines (35 loc) · 997 Bytes
/
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
require('dotenv').config()
var nodemailer = require('nodemailer');
// standard snippet for sending mails via gmail smtp
const Mailer = (to, sub, body) => {
const mailPass = process.env.EMAIL_PASS2;
const mail = process.env.EMAIL;
var transporter = nodemailer.createTransport({
service: 'gmail',
auth: {
user: mail,
pass: mailPass
}
});
var mailOptions = {
from: mail,
to: to,
subject: sub,
text: body,
};
try {
transporter.sendMail(mailOptions, function (error, info) {
if (error) {
console.log(error);
} else {
console.log('Email sent: ' + info.response);
res.status(200).json({ message: "Email Sent" });
return true
}
});
} catch (error) {
console.error(error.message);
res.status(500).send("Some error occured");
}
}
module.exports = Mailer