Refine suppression list to include only affected recipients (#339)
This commit is contained in:
@@ -115,12 +115,28 @@ export async function parseSesHook(data: SesEvent) {
|
|||||||
mailStatus === EmailStatus.BOUNCED &&
|
mailStatus === EmailStatus.BOUNCED &&
|
||||||
(mailData as SesBounce).bounceType === "Permanent";
|
(mailData as SesBounce).bounceType === "Permanent";
|
||||||
|
|
||||||
|
// Fix: Only add the actual bounced/complained recipients to suppression list
|
||||||
// Add emails to suppression list for hard bounces and complaints
|
// Add emails to suppression list for hard bounces and complaints
|
||||||
if (isHardBounced || mailStatus === EmailStatus.COMPLAINED) {
|
if (isHardBounced || mailStatus === EmailStatus.COMPLAINED) {
|
||||||
logger.info("Adding emails to suppression list");
|
logger.info("Adding emails to suppression list");
|
||||||
|
|
||||||
const recipientEmails = Array.isArray(email.to) ? email.to : [email.to];
|
// Get the actual affected recipients from the event data
|
||||||
|
let recipientEmails: string[] = [];
|
||||||
|
|
||||||
|
if (isHardBounced && data.bounce?.bouncedRecipients) {
|
||||||
|
// For bounces, only add the recipients that actually bounced
|
||||||
|
recipientEmails = data.bounce.bouncedRecipients.map(
|
||||||
|
(recipient) => recipient.emailAddress
|
||||||
|
);
|
||||||
|
} else if (mailStatus === EmailStatus.COMPLAINED && data.complaint?.complainedRecipients) {
|
||||||
|
// For complaints, only add the recipients that actually complained
|
||||||
|
recipientEmails = data.complaint.complainedRecipients.map(
|
||||||
|
(recipient) => recipient.emailAddress
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
// Only proceed if we have affected recipients
|
||||||
|
if (recipientEmails.length > 0) {
|
||||||
try {
|
try {
|
||||||
await Promise.all(
|
await Promise.all(
|
||||||
recipientEmails.map((recipientEmail) =>
|
recipientEmails.map((recipientEmail) =>
|
||||||
@@ -154,6 +170,15 @@ export async function parseSesHook(data: SesEvent) {
|
|||||||
);
|
);
|
||||||
// Don't throw error - continue processing the webhook
|
// Don't throw error - continue processing the webhook
|
||||||
}
|
}
|
||||||
|
} else {
|
||||||
|
logger.warn(
|
||||||
|
{
|
||||||
|
emailId: email.id,
|
||||||
|
eventType: data.eventType,
|
||||||
|
},
|
||||||
|
"No affected recipients found in bounce/complaint event data",
|
||||||
|
);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if (
|
if (
|
||||||
|
|||||||
Reference in New Issue
Block a user