-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmailer.js
45 lines (42 loc) · 1.18 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
const aws = require("aws-sdk"),
ses = new aws.SES(),
fs = require("fs"),
nodemailer = require("nodemailer");
module.exports = result => {
return new Promise((resolve, reject) => {
try {
if (Object.keys(result).length === 0) {
reject(new Error("empty"));
}
const template = require("./email_template.js")(result);
const response = {};
const mailOptions = {
from: "SES VERIFIED EMAIL",
subject: template.subject,
replyTo: result.email,
text: template.text,
html: template.html,
to: ["SES VERIFIED EMAIL", "ANOTHER SES VERIFIED EMAIL"],
attachments: result.files
};
const transporter = nodemailer.createTransport({
SES: ses
});
transporter.sendMail(mailOptions, (err, info) => {
if (err) {
reject(err);
} else {
console.log("Mailer sent successfully");
response.status = 200;
response.body = template.responseBody;
for (const file of result.files) {
fs.unlinkSync(file.path);
}
resolve(response);
}
});
} catch (err) {
reject(err);
}
});
};