- Neueste
- Die meisten Stimmen
- Die meisten Kommentare
I don't see the receipt node in the notification. receipt.recipients contains the envelope recipients (RCPT TO) for the message, which may differ from the message recipients (To:, CC: headers in the DATA). Some sending MTAs (i.e. Gmail) batch all recipients for a single domain in a single SMTP transaction (subject to an internal RCPT TO limit) and some MTAs (i.e. Yahoo) send a message for every recipient. The only way you'll know is by comparing the envelope recipients (receipt.recipients[]) with the message recipient headers (To:, CC:).
Can you help me, how can I check logs using message ID? Thanks!
I had the same issue, and I solved it by sending the result from SES to another SNS(fifo) and SQS(fifo) through a lambda function. We can use SES ID as deduplication ID to prevent duplicate notifications.
Code snippet for sending SNS
// handler
export const handler: SNSHandler = async (event) => {
const sentMessages= [];
event.Records.forEach((r) => {
const data = JSON.parse(r.Sns.Message);
const headers = (data?.mail?.headers || {}).reduce(
(acc, h) => {
acc[h.name] = h.value;
return acc;
},
{} as Record<HeaderName, string>,
);
const emailDelivered = data.notificationType === "Delivery";
if (emailDelivered) {
sentMessages.push({
job_id: headers.Job_id,
message: headers.Message,
receiverId: headers.Receiverid,
senderId: headers.Senderid,
subject: headers.Subject,
sesId: data.mail.messageId,
is_from_admin: isAdminEmail,
});
}
});
if (sentMessages.length === 0) {
console.log("No messages to send");
}
await sendSns(sentMessages);
return;
};
// sendSns
import { PublishBatchCommand, SNSClient } from "@aws-sdk/client-sns";
import { CreateMessageInput } from "./types";
const client = new SNSClient({});
const snsTopic = process.env.SNS_TOPIC_ARN!;
export const sendSns = async (sentMessages: CreateMessageInput[]) => {
// split the chunk into 10
// as the maximum number of entries in a single batch is 10
const chunkSize = 10;
const chunks = [];
for (let i = 0; i < sentMessages.length; i += chunkSize) {
chunks.push(sentMessages.slice(i, i + chunkSize));
}
for (const [id, chunk] of chunks.entries()) {
const command = new PublishBatchCommand({
TopicArn: snsTopic,
PublishBatchRequestEntries: chunk.map((message, index) => ({
Id: `${id}-${index}`,
Message: JSON.stringify(message),
MessageGroupId: "email-delivered",
MessageDeduplicationId: message.sesId!, //sesId should exist and unique per message
})),
});
try {
const response = await client.send(command);
console.log("response: ", JSON.stringify(response, null, 2));
} catch (error) {
console.error("Failed to send batch message: ", error);
}
}
};
Reference: https://docs.aws.amazon.com/sns/latest/dg/fifo-message-dedup.html
Relevanter Inhalt
- AWS OFFICIALAktualisiert vor 2 Jahren
- AWS OFFICIALAktualisiert vor 2 Jahren
- AWS OFFICIALAktualisiert vor 2 Jahren
- AWS OFFICIALAktualisiert vor 10 Monaten
Any updates on this? i'm having exactly the same problem! one email sent to aws ses. Somehow, we're getting multiple open notifications with different message ids!