This commit is contained in:
Patrick Fic
2021-08-19 17:31:32 -07:00
parent 61a5e180f4
commit 5a4d6d3e8c
21 changed files with 301 additions and 610 deletions

View File

@@ -8,7 +8,7 @@ require("dotenv").config({
const axios = require("axios");
let nodemailer = require("nodemailer");
let aws = require("aws-sdk");
const logger = require("../utils/logger");
const ses = new aws.SES({
apiVersion: "2010-12-01",
region: "ca-central-1",
@@ -19,9 +19,13 @@ let transporter = nodemailer.createTransport({
});
exports.sendEmail = async (req, res) => {
if (process.env.NODE_ENV !== "production") {
console.log("[EMAIL] Incoming Message", req.body.from.name);
}
logger.log("send-email", "DEBUG", req.user.email, null, {
from: `${req.body.from.name} <${req.body.from.address}>`,
replyTo: req.body.ReplyTo.Email,
to: req.body.to,
cc: req.body.cc,
subject: req.body.subject,
});
let downloadedMedia = [];
if (req.body.media && req.body.media.length > 0) {
@@ -30,7 +34,14 @@ exports.sendEmail = async (req, res) => {
try {
return getImage(m);
} catch (error) {
console.log(error);
logger.log("send-email-error", "ERROR", req.user.email, null, {
from: `${req.body.from.name} <${req.body.from.address}>`,
replyTo: req.body.ReplyTo.Email,
to: req.body.to,
cc: req.body.cc,
subject: req.body.subject,
error,
});
}
})
);
@@ -73,10 +84,26 @@ exports.sendEmail = async (req, res) => {
(err, info) => {
console.log(err || info);
if (info) {
console.log("[EMAIL] Email sent: " + info);
logger.log("send-email-success", "DEBUG", req.user.email, null, {
from: `${req.body.from.name} <${req.body.from.address}>`,
replyTo: req.body.ReplyTo.Email,
to: req.body.to,
cc: req.body.cc,
subject: req.body.subject,
info,
});
res.json({ success: true, response: info });
} else {
console.log("[EMAIL] Email send failed. ", err);
logger.log("send-email-failure", "ERROR", req.user.email, null, {
from: `${req.body.from.name} <${req.body.from.address}>`,
replyTo: req.body.ReplyTo.Email,
to: req.body.to,
cc: req.body.cc,
subject: req.body.subject,
error: err,
});
res.json({ success: false, error: err });
}
}