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.

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.

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

Configuring DMARC

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.

const api = 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()
}

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.identity?

Type EmailIdentityArgs | (args: EmailIdentityArgs => void)

Transform the SES identity resource.

Properties

nodes

Type Object

The underlying resources this component creates.

nodes.identity

Type EmailIdentity

The Amazon SES identity.

sender

Type Output<string>

The sender email address or domain name.

SDK

The following are accessible through the SDK at runtime.

  • sender string

    The sender email address or domain name.