Skip to content

EmailIdentity

Source: src/AWS/SES/EmailIdentity.ts

An Amazon SES v2 email identity — a verified email address or domain that you send email from.

Creating the identity starts verification: email-address identities receive a verification email, and domain identities get Easy DKIM tokens (exposed as the dkimTokens attribute) to publish as CNAME records. The identity is usable for sending once verificationStatus is SUCCESS.

Domain Identity

import * as SES from "alchemy/AWS/SES";
const identity = yield* SES.EmailIdentity("Sender", {
emailIdentity: "mail.example.com",
});
// publish identity.dkimTokens as CNAME records to verify

Email Address Identity

const identity = yield* SES.EmailIdentity("Sender", {
emailIdentity: "hello@example.com",
});
// SES emails hello@example.com a verification link
const configSet = yield* SES.ConfigurationSet("Tracking", {});
const identity = yield* SES.EmailIdentity("Sender", {
emailIdentity: "mail.example.com",
configurationSetName: configSet.configurationSetName,
});

Turn Easy DKIM Signing Off

// Omit the prop entirely to leave SES's current setting alone.
const identity = yield* SES.EmailIdentity("Sender", {
emailIdentity: "mail.example.com",
dkimSigningEnabled: false,
});

Stop Forwarding Bounces and Complaints by Email

// Turn this off once a configuration set event destination is handling
// bounces and complaints, so they stop arriving as mail.
const identity = yield* SES.EmailIdentity("Sender", {
emailIdentity: "mail.example.com",
feedbackForwardingEnabled: false,
});
// mailFromDomain must be a subdomain of the identity, and needs MX and
// SPF records published before SES will use it.
const identity = yield* SES.EmailIdentity("Sender", {
emailIdentity: "mail.example.com",
mailFromDomain: "bounce.mail.example.com",
// Reject rather than silently falling back to the SES default when the
// MX record cannot be read.
mailFromBehaviorOnMxFailure: "REJECT_MESSAGE",
});
// init
const sendEmail = yield* SES.SendEmail(identity);
// runtime
const result = yield* sendEmail({
FromEmailAddress: "hello@mail.example.com",
Destination: { ToAddresses: ["customer@example.com"] },
Content: {
Simple: {
Subject: { Data: "Welcome!" },
Body: { Text: { Data: "Hello from SES." } },
},
},
});