Merged in release/2022-09-23 (pull request #584)

Updates to bounced email tracker.
This commit is contained in:
Patrick Fic
2022-09-23 21:03:19 +00:00

View File

@@ -209,15 +209,15 @@ async function logEmail(req, email) {
exports.emailBounce = async function (req, res, next) {
try {
const body = JSON.parse(req.body);
if (body.type !== "Notification") {
if (body.Type === "SubscriptionConfirmation") {
logger.log("SNS-message", "DEBUG", "api", null, {
body: req.body,
});
}
if (body.Type === "Notification") {
const message = JSON.parse(body.Message);
if (body.notificationType === "Bounce") {
// const message = JSON.parse(body.Message);
let replyTo, subject, messageId;
message.mail.headers.forEach((header) => {
body.mail.headers.forEach((header) => {
if (header.name === "Reply-To") {
replyTo = header.value;
} else if (header.name === "Subject") {
@@ -230,7 +230,7 @@ exports.emailBounce = async function (req, res, next) {
const result = await client.request(queries.UPDATE_EMAIL_AUDIT, {
sesid: messageId,
status: "Bounced",
context: message.bounce?.bouncedRecipients,
context: body.bounce?.bouncedRecipients,
});
transporter.sendMail(
{
@@ -240,7 +240,7 @@ exports.emailBounce = async function (req, res, next) {
subject: `ImEX Online Bounced Email - RE: ${subject}`,
text: `ImEX Online has tried to deliver an email with the subject: ${subject} to the intended recipients but encountered an error.
${message.bounce?.bouncedRecipients.map(
${body.bounce?.bouncedRecipients.map(
(r) =>
`Recipient: ${r.emailAddress} | Status: ${r.action} | Code: ${r.diagnosticCode}
`