/
mailer.js
36 lines (33 loc) · 1014 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
// This module uses nodemailer to generate email notifications
// on successful submission in app.js
// See https://nodemailer.com/about/ for more details
const nodemailer = require('nodemailer');
require('dotenv').config();
module.exports = {
notifyUser: (recipient) => {
// Send via Gmail
const transporter = nodemailer.createTransport({
service: 'gmail',
// Email service credentials
auth: {
user: `${process.env.MAIL_SERVICE_USER}`,
pass: `${process.env.MAIL_SERVICE_PW}`,
},
});
const mailOptions = {
from: 'vip.notifications1@gmail.com',
// recipient email address passed for app.js user submission
to: recipient,
subject: 'VIP Support',
// Email template to be sent
html: { path: './template.html' },
};
transporter.sendMail(mailOptions, function (error, info) {
if (error) {
console.log(error);
} else {
console.log('Email sent: ' + info.response);
}
});
},
};