Docs

Email

Email is a resource for sending and receiving mail on your customers' own domains, with their sending reputation, through Amazon SES in their AWS account. It fits transactional mail, notifications, or an email-first product where each customer brings a domain.

alien.ts
import * as alien from "@alienplatform/core"

const mailbox = new alien.Storage("mailbox").build()
const mailEvents = new alien.Queue("mail-events").build()

// Domains are added at runtime through email/manage-identities.
const mailer = new alien.Email("mailer")
  .inbound(mailbox)
  .events(mailEvents)
  .build()

const api = new alien.Worker("api")
  .code({ type: "source", src: "./api", toolchain: { type: "typescript" } })
  .link(mailer)
  .permissions("execution")
  .build()

export default new alien.Stack("acme")
  .platforms(["aws"])
  .add(mailbox, "frozen")
  .add(mailEvents, "frozen")
  .add(mailer, "frozen")
  .add(api, "live")
  .permissions({
    profiles: { execution: { mailer: ["email/send", "email/manage-identities"] } },
  })
  .build()

In this stack:

  • .link(mailer) connects the Email resource to the api Worker, the workload (the running code) that uses it. Alien injects the Email resource's connection details, its binding, into the Worker, which the AWS SDK uses directly.
  • The execution permission profile, the named set of cloud permissions a workload runs with, grants email/send and email/manage-identities.
  • "frozen" means the customer's admin creates the Email resource during initial setup. "live" resources, like the Worker, are created and updated by Alien on every release. See Frozen and live.

The api Worker sends with the AWS SDK and the configuration set from its binding. There is no Alien send API:

api/src/mail.ts
import { SESv2Client, SendEmailCommand } from "@aws-sdk/client-sesv2"

const { region, configurationSet } = JSON.parse(process.env.ALIEN_MAILER_BINDING!)

await new SESv2Client({ region }).send(new SendEmailCommand({
  ConfigurationSetName: configurationSet,
  FromEmailAddress: "hello@mail.example.com",
  Destination: { ToAddresses: ["someone@example.org"] },
  Content: { Simple: { Subject: { Data: "Hello" }, Body: { Text: { Data: "Hi there." } } } },
}))

A product with a fixed set of domains can create their identities at initial setup:

const mailer = new alien.Email("mailer").domains(["mail.example.com"]).build()

Platforms

mailer becomes SES infrastructure in the customer's AWS account: a configuration set, DKIM-verified domain identities, and optional inbound and event wiring.

PlatformBacking service
AWSAmazon SES
GCP, Azure, Kubernetes, Machines, LocalNot available

Frozen only

Email is always "frozen": the customer's admin creates it during initial setup. See Frozen and live.

The linked Storage and Queue must be frozen too, since initial setup wires them together.

Domains

The resource owns the email infrastructure: the configuration set, the event wiring, and the inbound wiring. It doesn't own the domain lifecycle.

  • Domains added at runtime: your app manages SES identities through the email/manage-identities permission set. See Customer-added domains.
  • A fixed set of domains: create their identities during initial setup with .domains().
const mailer = new alien.Email("mailer").domains(["mail.example.com"]).build()

Options

MethodTypeDefaultNotes
new alien.Email(id)string[A-Za-z0-9-_], up to 64 characters. Immutable.
.domains(list)string[][]Seed domains created at initial setup, one SES identity each with Easy DKIM. Replaces the list.
.domain(d)stringAdds one seed domain.
.inbound(storage)Storage resourcenoneWrites raw incoming MIME messages to the bucket.
.events(queue)Queue resourcenoneDelivers sending events to the queue. With .inbound(), the queue also receives SES Received notifications.
.enabled(input)boolean stack inputalways

domains may be empty. A configuration-set-only resource is valid.

Domain verification

Each seed domain gets an SES identity with Easy DKIM. The resource outputs carry three DKIM CNAME records per seed domain. Create them in the domain's DNS, and SES verifies the domain once they exist.

For identities your app creates at runtime, read the DKIM tokens from the CreateEmailIdentity response and hand them to the customer.

Use it in code

Send with the AWS SDK and the configuration set from the binding, as the api Worker does above. There is no Alien send API.

The workload's credentials come from its permission profile, so there are no keys to configure. See the API reference for the binding, runtime domain management, inbound mail, and events.

Common patterns

Customer-added domains

No stack change is needed when a customer adds a domain in your product:

  1. Your app creates the SES identity.
  2. Your product shows the customer the three DKIM records.
  3. Your app polls verification.
  4. When the customer removes the domain, your app deletes the identity.

Inbound processing

Link a bucket with .inbound() and a queue with .events(). Each received message arrives in the queue as a Received notification with its envelope recipients and the object key of the raw message in the bucket.

Bounce handling

Consume Bounce and Complaint events from the events queue and suppress those addresses in your app.

Permissions

SetGrants
email/sendses:SendEmail and ses:SendRawEmail.
email/manage-identitiesCreating, reading, listing, configuring, and deleting SES identities at runtime.
email/managementReading identity status, the configuration set, and receipt rules.
email/heartbeatChecking that the inbound receipt rule set is still active.
email/provisionCreating the SES resources at initial setup.

Next

On this page