How to add custom headers to send emails?

I am using AWS SES, i want to add my configuration set to send emails through a dedicated IP pool and override the suppression reason.

Hi @patra.prerna31

Welcome to the Auth0 Community!

I am sorry about the late reply to your post.

As far as I have researched regarding the SES custom headers, it appears that you will need to use a RawMessage in order to add them. You basically need to add a header to the SES API call, not the message itself. You can refer to this post regarding the same issue.
On the other hand, Amazon SES appears to allow you to see the custom headers in the notifications received due to bounces, complaints or unsubscribe responses which you will need to enable this feature for any domain as seen below:

The Amazon SES team is pleased to announce the addition of original email headers to the bounce, complaint, and delivery notifications SES provides through Amazon SNS.

We strive to make your email-sending process easier, and today we’re taking another step in that direction. Increasing your visibility into the feedback you receive from SES has always been a key focus for us. Starting today, the headers you pass to SES in your email-sending requests can be made available in your SNS notifications. Read on for answers to some common questions.

How do I enable this feature?

Use the Amazon SES console or API to configure the notification settings for an identity (email address or domain) and notification type (bounce, complaint, or delivery).

For example, to use the SES console to include the original headers for an identity’s bounce notifications, you’d go to the notification settings for an identity and select Include original headers next to the bounce notification configuration:

After this feature is enabled, the notifications will contain the headers in both raw name/value format and in JSON format for commonly provided headers.

I was able to find this example code below regarding sending custom messages using a custom header which I believe might be helpful:

import { SESv2Client ,SendEmailCommand }  from "@aws-sdk/client-sesv2"

const sesV2Client = new SESv2Client({ region: "us-west-2" });

const sender = 'sender@example.com';
const recipient = 'recipient@example.com'

async function sendRawEmailWithCustomHeader() {
    const rawMessageData = `From: ${sender}\nTo: ${recipient}\nSubject: Hello World with Custom Header\nMIME-Version: 1.0\nContent-Type: text/plain; charset="UTF-8"\nX-custom-header: foo\n\nHello world`;

    try {
        const data = await sesV2Client.send(new SendEmailCommand({
            Content: {
                Raw: {
                    Data: Buffer.from(rawMessageData)
                }
            }
        }));
        console.log(data.MessageId);
    } catch (error) {
        console.error(error);
    }
}
sendRawEmailWithCustomHeader();

Otherwise, you can review the AWS documentation regarding sending custom headers:

Hope the information above is useful for your implementation.
If you have any extra questions on the matter or if the issue was already resolved, feel free to drop a reply or post again on the community page!

Kind Regards,
Nik

This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.