Nov 18, 20266 min read

How to Send Transactional Email With Amazon SES From Your Backend

Verify a domain with DKIM, leave the SES sandbox, send through the SESv2 API or SMTP from Go, queue sends so a slow provider does not block requests, and handle bounces and complaints.

Illustration for How to Send Transactional Email With Amazon SES From Your Backend

Amazon SES sends password resets, receipts and alerts from a backend on AWS for $0.10 per 1,000 emails, and the API call itself is short. The effort sits around it: proving the domain is yours and leaving the sandbox, plus keeping a throttling error from failing the request that triggered the email.

This guide covers the setup in order, shows both the SESv2 API and the SMTP route from Go, and then builds the send queue with Encore, where the topic, the retry policy and the SMTP credentials are part of the application.

SES setup at a glance

StepWhat you doWhy it matters
Domain identityVerify mail.example.com and publish three Easy DKIM CNAMEsMail is signed and passes DKIM
SPF and DMARCOptional custom MAIL FROM domain, plus a DMARC TXT recordAlignment for DMARC and better inbox placement
Sandbox exitRequest production access per RegionSandbox caps you at 200 messages a day to verified addresses
Sending identityIAM role with ses:SendEmail, or SMTP credentialsThe backend can authenticate to SES
QueuePublish a message, send in a subscriber with retriesRequests do not wait on SES and failures retry
FeedbackConfiguration set events for bounces and complaintsKeeps bounce and complaint rates under SES limits

Step 1: Verify the domain

Create a domain identity in the SES console or with the CLI, then publish the three CNAME records SES returns. Easy DKIM signs every message with a key that AWS rotates.

aws sesv2 create-email-identity \ --email-identity mail.example.com \ --region eu-west-1 aws sesv2 get-email-identity \ --email-identity mail.example.com \ --region eu-west-1 \ --query 'DkimAttributes.Tokens'

Each token becomes a record of the form TOKEN._domainkey.mail.example.com CNAME TOKEN.dkim.amazonses.com. Add a DMARC record such as _dmarc.example.com TXT "v=DMARC1; p=none; rua=mailto:dmarc@example.com" to start monitoring, and tighten the policy once reports look clean. A custom MAIL FROM domain gives SPF alignment as well.

Step 2: Leave the sandbox

New accounts start in the SES sandbox: mail only goes to verified addresses and domains or the mailbox simulator, with a maximum of 200 messages per 24 hours and 1 message per second. The sandbox is per Region. Request production access in the console with a short description of the mail you send, how recipients opt in and how you handle bounces, and test against the mailbox simulator addresses such as bounce@simulator.amazonses.com meanwhile.

Step 3: Send from Go

With the SESv2 API, the backend authenticates through its IAM role, and the role needs ses:SendEmail on the identity, as in this call with the AWS SDK for Go v2:

package mail import ( "context" "github.com/aws/aws-sdk-go-v2/aws" "github.com/aws/aws-sdk-go-v2/config" "github.com/aws/aws-sdk-go-v2/service/sesv2" "github.com/aws/aws-sdk-go-v2/service/sesv2/types" ) func SendReceipt(ctx context.Context, to, subject, text string) error { cfg, err := config.LoadDefaultConfig(ctx, config.WithRegion("eu-west-1")) if err != nil { return err } client := sesv2.NewFromConfig(cfg) _, err = client.SendEmail(ctx, &sesv2.SendEmailInput{ FromEmailAddress: aws.String("Acme <receipts@mail.example.com>"), Destination: &types.Destination{ToAddresses: []string{to}}, Content: &types.EmailContent{ Simple: &types.Message{ Subject: &types.Content{Data: aws.String(subject)}, Body: &types.Body{Text: &types.Content{Data: aws.String(text)}}, }, }, ConfigurationSetName: aws.String("transactional"), }) return err }

The alternative is the SES SMTP interface at email-smtp.eu-west-1.amazonaws.com on port 587 with STARTTLS. SMTP credentials are generated from an IAM user in the SES console, which makes them a long-lived secret to store and rotate, while any SMTP library works and the service needs no SES permission on its own role.

Step 4: Queue the send

Calling SES inside the request handler ties the response time to SES, and a throttling error or timeout turns into a failed signup. A queue between the two fixes both: the endpoint publishes a message and returns, and a subscriber sends with retries and backoff. SES does not deduplicate sends, so a retry after a timeout can deliver the same email twice, and for receipts it is worth recording the message ID in the database before sending.

Step 5: Handle bounces and complaints

Create a configuration set, add an event destination for BOUNCE and COMPLAINT to an SNS topic, and suppress addresses that hard-bounce or complain. The account-level suppression list does part of this automatically. SES reviews accounts whose bounce or complaint rates climb, as described in the sending review docs, so feedback handling is part of keeping the account able to send.

How do you build the send queue with Encore?

Encore

Encore brings infrastructure from code, and for email that means the queue, its retry policy and the SMTP credentials are declared in the Go service that sends the mail. The topic and subscription are Pub/Sub declarations, which encore run runs locally and which Encore provisions as SNS and SQS with a dead-letter queue in your AWS account, as the AWS infrastructure docs describe. The SMTP username and password are Encore secrets, stored in AWS Secrets Manager in your account and injected at runtime.

Application code passes through Encore and infrastructure guardrails to resources provisioned in your own AWS or GCP account.
Get started
brew install encoredev/tap/encore &&
encore app create
Copy

Run in your terminal to get started locally.

// email/email.go package email import ( "context" "errors" "fmt" "net/smtp" "strings" "time" "encore.dev/pubsub" ) var secrets struct { SESSMTPUsername string SESSMTPPassword string } const ( smtpHost = "email-smtp.eu-west-1.amazonaws.com" fromAddr = "receipts@mail.example.com" ) type Message struct { To string `json:"to"` Subject string `json:"subject"` Text string `json:"text"` } var Outbox = pubsub.NewTopic[*Message]("email-outbox", pubsub.TopicConfig{ DeliveryGuarantee: pubsub.AtLeastOnce, }) var _ = pubsub.NewSubscription(Outbox, "send-via-ses", pubsub.SubscriptionConfig[*Message]{ Handler: send, AckDeadline: 30 * time.Second, RetryPolicy: &pubsub.RetryPolicy{ MinBackoff: 30 * time.Second, MaxBackoff: 10 * time.Minute, MaxRetries: 10, }, }) // Enqueue is called by other services, for example after a signup. //encore:api private method=POST path=/email func Enqueue(ctx context.Context, m *Message) error { if strings.ContainsAny(m.To+m.Subject, "\r\n") { return errors.New("invalid header value") } _, err := Outbox.Publish(ctx, m) return err } func send(ctx context.Context, m *Message) error { auth := smtp.PlainAuth("", secrets.SESSMTPUsername, secrets.SESSMTPPassword, smtpHost) msg := strings.Join([]string{ "From: Acme <" + fromAddr + ">", "To: " + m.To, "Subject: " + m.Subject, "MIME-Version: 1.0", "Content-Type: text/plain; charset=UTF-8", "", m.Text, }, "\r\n") if err := smtp.SendMail(smtpHost+":587", auth, fromAddr, []string{m.To}, []byte(msg)); err != nil { return fmt.Errorf("send via ses: %w", err) // retried with backoff } return nil }

Set the two secrets once per environment type, for example encore secret set --type prod SESSMTPUsername and the same for the password, and a deploy fails if either is missing. Production values are not stored in the repository, so a coding agent working in it cannot read or leak those production SMTP credentials. A local override in .secrets.local.cue is a file on disk and is readable if it is present. An agent that adds a new kind of email only publishes to Outbox from the service it is working on. smtp.SendMail upgrades the connection with STARTTLS before it authenticates, which SES requires on port 587.

The SMTP route keeps the example inside what Encore declares for you. If you prefer the SESv2 API from Step 3, Encore provisions an IAM role for the service, and the ses:SendEmail permission on that role is something you grant in AWS yourself.

Best fit: Go or TypeScript backends on AWS that want email sends queued, retried and dead-lettered, with the provider credentials kept out of the repository.

Frequently asked questions

How do I send email with Amazon SES?

Verify a sending domain in SES and publish the three Easy DKIM CNAME records, request production access to leave the sandbox, then call the SESv2 SendEmail API with an IAM principal that has ses:SendEmail, or send through the SES SMTP endpoint with SMTP credentials. Put the send behind a queue so a slow or failing SES call is retried instead of failing the user's request.

What are the SES sandbox limits?

In the sandbox you can only send to verified addresses and domains or the SES mailbox simulator, up to 200 messages per 24 hours and 1 message per second. The sandbox status is per AWS Region, so production access has to be requested in each Region you send from.

How much does Amazon SES cost?

SES pricing page, checked on November 18, 2026: a la carte outbound email is $0.10 per 1,000 emails plus $0.12 per GB of attachments, and the newer plans start at $0.16 per 1,000 emails on Essentials. Dedicated IPs and other features are billed separately.

How do I queue SES emails with Encore?

Declare a Pub/Sub topic and a subscription with a retry policy in Go, publish a message from the endpoint, and send through SES in the subscriber with SMTP credentials stored as Encore secrets. encore run runs the topic locally, and on AWS Encore provisions SNS and SQS with a dead-letter queue for the subscription.

Deploy to your cloud on AWS and Google Cloud
without managing infrastructure

Encore lets developers and agents define application infrastructure directly in code, then automatically provisions it from local development to production in your AWS or GCP account.

~/orders — claude
Claude Code
Claude Code v2.1.180Opus 5.5~/orders