-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmailer.js
47 lines (39 loc) · 1.04 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
const nodemailer = require('nodemailer');
const { HOST_NAME, EMAIL, PASSWORD } = require('./config');
const smtpConfig = {
host: HOST_NAME,
port: '587',
secure: false,
requireTLS: true,
auth: {
user: EMAIL,
pass: PASSWORD
}
};
const transporter = nodemailer.createTransport(smtpConfig);
const defaultMail = {
from: EMAIL,
to: EMAIL,
subject: 'General Comment',
text: 'n/a',
html: '<p>n/a</p>'
};
const sendEmail = (mailOptions) => {
return transporter.sendMail(mailOptions || defaultMail, (error, info) => {
if(error){
return console.log('Error encountered: ' + error);
}
console.log('Message sent: ' + info.response);
});
};
const sendFeedbackEmailToCorrectAddress = (event, context) => {
const data = {
from: defaultMail.from,
to: defaultMail.to,
subject: event.body.subject || defaultMail.subject,
text: event.body.text || defaultMail.text,
html: event.body.html || defaultMail.html
};
sendEmail(data);
};
exports.sendFeedbackEmail = sendFeedbackEmailToCorrectAddress;