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) { exports.emailBounce = async function (req, res, next) {
try { try {
const body = JSON.parse(req.body); const body = JSON.parse(req.body);
if (body.type !== "Notification") { if (body.Type === "SubscriptionConfirmation") {
logger.log("SNS-message", "DEBUG", "api", null, { logger.log("SNS-message", "DEBUG", "api", null, {
body: req.body, body: req.body,
}); });
} }
if (body.Type === "Notification") { if (body.notificationType === "Bounce") {
const message = JSON.parse(body.Message); // const message = JSON.parse(body.Message);
let replyTo, subject, messageId; let replyTo, subject, messageId;
message.mail.headers.forEach((header) => { body.mail.headers.forEach((header) => {
if (header.name === "Reply-To") { if (header.name === "Reply-To") {
replyTo = header.value; replyTo = header.value;
} else if (header.name === "Subject") { } 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, { const result = await client.request(queries.UPDATE_EMAIL_AUDIT, {
sesid: messageId, sesid: messageId,
status: "Bounced", status: "Bounced",
context: message.bounce?.bouncedRecipients, context: body.bounce?.bouncedRecipients,
}); });
transporter.sendMail( transporter.sendMail(
{ {
@@ -240,7 +240,7 @@ exports.emailBounce = async function (req, res, next) {
subject: `ImEX Online Bounced Email - RE: ${subject}`, 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. 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) => (r) =>
`Recipient: ${r.emailAddress} | Status: ${r.action} | Code: ${r.diagnosticCode} `Recipient: ${r.emailAddress} | Status: ${r.action} | Code: ${r.diagnosticCode}
` `