From ac270a608f86a17d5f251c0dddad17e8a7c30100 Mon Sep 17 00:00:00 2001 From: Patrick Fic Date: Fri, 23 Sep 2022 13:59:58 -0700 Subject: [PATCH] Updates to bounced email tracker. --- server/email/sendemail.js | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/server/email/sendemail.js b/server/email/sendemail.js index dc2387b1f..277915d17 100644 --- a/server/email/sendemail.js +++ b/server/email/sendemail.js @@ -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} `