Fixed an issue where emails sent to multiple recipients (CC/BCC) were not being found in S3 storage due to incorrect domain detection logic.
Our Lambda function was failing to process emails when they were sent to multiple recipients across different domains. The function would only check the first recipient's domain when searching for emails in S3, causing failures for BCC'd emails or emails sent to multiple domains.
The Lambda now considers all recipients when determining where to search for emails:
Previously, the Lambda used this logic:
const recipientEmail = recipients[0] || '';
const domain = recipientEmail.split('@')[1] || '';
Now it uses comprehensive recipient detection:
const allEmails = [...new Set([
...allRecipients,
...toRecipients.map(r => typeof r === 'string' ? r : r.address),
...ccRecipients.map(r => typeof r === 'string' ? r : r.address),
...bccRecipients.map(r => typeof r === 'string' ? r : r.address)
])];
const domains = [...new Set(
allEmails.map(email => email.match(/@([^@\s]+)$/)?.[1]).filter(Boolean)
)];
This fix ensures that:
No action is required from users - this fix is automatically deployed to all Lambda functions.