Skip to content

Email

Reference doc for the `sst.aws.Email` component.

The Email component lets you send emails in your app. It uses Amazon Simple Email Service.

You can configure it to send emails from a specific email address or from any email addresses in a domain.

By default, new AWS SES accounts are in the sandbox mode and can only send email to verified email addresses and domains. It also limits your account has to a sending quota. To remove these restrictions, you need to request production access.

Sending from an email address

For using an email address as the sender, you need to verify the email address.

sst.config.ts
const email = new sst.aws.Email("MyEmail", {
sender: "spongebob@example.com",
});

Sending from a domain

When you use a domain as the sender, you’ll need to verify that you own the domain.

sst.config.ts
new sst.aws.Email("MyEmail", {
sender: "example.com"
});

Configuring DMARC

sst.config.ts
new sst.aws.Email("MyEmail", {
sender: "example.com",
dmarc: "v=DMARC1; p=quarantine; adkim=s; aspf=s;"
});

You can link it to a function or your Next.js app to send emails.

sst.config.ts
new sst.aws.Function("MyApi", {
handler: "sender.handler",
link: [email]
});

Now in your function you can use the AWS SES SDK to send emails.

sender.ts
import { Resource } from "sst";
import { SESv2Client, SendEmailCommand } from "@aws-sdk/client-sesv2";
const client = new SESv2Client();
await client.send(
new SendEmailCommand({
FromEmailAddress: Resource.MyEmail.sender,
Destination: {
ToAddresses: ["patrick@example.com"]
},
Content: {
Simple: {
Subject: { Data: "Hello World!" },
Body: { Text: { Data: "Sent from my SST app." } }
}
}
})
);

Constructor

new Email(name, args, opts?)

Parameters

EmailArgs

dmarc?

Type Input<string>

Default “v=DMARC1; p=none;”

The DMARC policy for the domain. This’ll create a DNS record with the given DMARC policy. Only specify this if you are using a domain name as the sender.

{
dmarc: "v=DMARC1; p=quarantine; adkim=s; aspf=s;"
}

dns?

Type Input<false | sst.aws.dns | sst.cloudflare.dns | sst.vercel.dns>

Default sst.aws.dns

The DNS adapter you want to use for managing DNS records. Only specify this if you are using a domain name as the sender.

Specify the hosted zone ID for the domain.

{
dns: sst.aws.dns({
zone: "Z2FDTNDATAQYW2"
})
}

Domain is hosted on Cloudflare.

{
dns: sst.cloudflare.dns()
}

events?

Type Input<Object[]>

Default No event notifications

Configure event notifications for this Email component.

{
events: {
name: "OnBounce",
types: ["bounce"],
topic: "arn:aws:sns:us-east-1:123456789012:MyTopic"
}
}

events[].bus?

Type Input<string>

The ARN of the EventBridge bus to send events to.

events[].name

Type Input<string>

The name of the event.

events[].topic?

Type Input<string>

The ARN of the SNS topic to send events to.

events[].types

Type Input<Input<send | reject | bounce | complaint | delivery | delivery-delay | rendering-failure | subscription | open | click>[]>

The types of events to send.

sender

Type Input<string>

The email address or domain name that you want to send emails from.

Using an email address as the sender. You’ll need to verify the email address. When you deploy your app, you will receive an email from AWS SES with a link to verify the email address.

{
sender: "john.smith@gmail.com"
}

Using a domain name as the sender. You’ll need to verify that you own the domain. Once you verified, you can send emails from any email addresses in the domain.

To verify the domain, you need to add the verification records to your domain’s DNS. This can be done automatically for the supported dns adapters.

{
sender: "example.com"
}

If the domain is hosted on Cloudflare.

{
sender: "example.com",
dns: sst.cloudflare.dns()
}

transform?

Type Object

Transform how this component creates its underlying resources.

transform.configurationSet?

Type ConfigurationSetArgs | (args: ConfigurationSetArgs, opts: ComponentResourceOptions, name: string) => void

Transform the SES configuration set resource.

transform.identity?

Type EmailIdentityArgs | (args: EmailIdentityArgs, opts: ComponentResourceOptions, name: string) => void

Transform the SES identity resource.

Properties

configSet

Type Output<string>

The name of the configuration set.

nodes

Type Object

The underlying resources this component creates.

nodes.configurationSet

Type ConfigurationSet

The Amazon SES configuration set.

nodes.identity

Type EmailIdentity

The Amazon SES identity.

sender

Type Output<string>

The sender email address or domain name.

SDK

Use the SDK in your runtime to interact with your infrastructure.


This is accessible through the Resource object in the SDK.

  • configSet string

    The name of the configuration set.

  • sender string

    The sender email address or domain name.

Methods

static get

Email.get(name, sender, opts?)

Parameters

  • name string

    The name of the component.
  • sender Input<string>

    The email address or domain name of the existing SES identity.
  • opts? ComponentResourceOptions

Returns Email

Reference an existing Email component with the given Amazon SES identity. This is useful when you create an SES identity in one stage and want to share it in another stage. It avoids having to create a new Email component in the other stage.

Imagine you create an Email component in the dev stage. And in your personal stage frank, instead of creating a new component, you want to share the one from dev.

sst.config.ts
const email = $app.stage === "frank"
? sst.aws.Email.get("MyEmail", "spongebob@example.com")
: new sst.aws.Email("MyEmail", {
sender: "spongebob@example.com",
});