I'm using aws Javascript SDK to send bulk emails.
However, I need to add unsubscribe headers, which I'm unsure how to
Here is my code:
import { SendBulkTemplatedEmailCommand } from "@aws-sdk/client-ses";
import { SESClient } from "@aws-sdk/client-ses";
const createBulkReminderEmailCommand = (users, templateName) => {
return new SendBulkTemplatedEmailCommand({
Destinations: users.map((user) => {
// do something
return {
Destination: { ToAddresses: [user] },
ReplacementTemplateData: JSON.stringify({ hashedUser }),
// adding this does not work
// Headers: [
// {
// Name: "List-Unsubscribe",
// Value: `<https://domain.tld/unsubscribe?id=${hashedUser}>, <mailto:unsub@mail.domain.tld?subject=TopicUnsubscribe>`
// },
// {
// Name: "List-Unsubscribe-Post",
// Value: "List-Unsubscribe=One-Click"
// }
// ]
};
}),
DefaultTemplateData: JSON.stringify({}),
Source: VERIFIED_EMAIL,
Template: templateName,
ConfigurationSetName: "grow",
});
};
const sendBulkTemplateEmailCommand = createBulkReminderEmailCommand(
emails,
TEMPLATE_NAME
);
const res = await sesClient.send(sendBulkTemplateEmailCommand);
I've also checked this documentation, however, it is giving solution for python, and not javascript.
If you need further info, please let me know in the comments!
It is possible with @aws-sdk/client-sesv2
See docs for sesv2 client, specifically the SendEmailCommand