-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathemail.js
31 lines (28 loc) · 1.1 KB
/
email.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
const nodemailer = require('nodemailer');
// imported to manager_controller
module.exports = function sendEmail(subj, email, output) {
// async..await is not allowed in global scope, must use a wrapper
async function mainEmail() {
// create reusable transporter object using the default SMTP transport
const transporter = nodemailer.createTransport({
service: 'gmail',
auth: {
user: '[email protected]', // gmail user - implement npm dotenv + .env file
pass: process.env.EMAIL_PASS, // gmail password - implement npm dotenv + .env file
},
});
// send mail with defined transport object
const info = await transporter.sendMail({
from: '[email protected]', // sender address
to: email, // list of receivers
cc: '[email protected]',
subject: subj, // Subject line
text: 'This is a breakaway test', // plain text body
html: output, // html body
});
// DO NOT REMOVE THE LINE BELOW
console.log('Email sent: %s', info.messageId);
// DO NOT REMOVE THE LINE ABOVE
}
mainEmail().catch(console.error);
};