Nishara Ramasinghe
HI-FI
◂ PostsAWS SES with Supabase Auth: Production-Ready Invite and Password Reset Emails
StartThe short versionHow the pieces fitSES with AWS CDKDomain identity, and the sandboxDNS: five records, three silent failuresSMTP credentials: derive, then test outside SupabaseSupabase custom SMTPLink scanners spend your one-time tokensTemplates and expiry live in the project, not the repoGo-live checklistWhat I took awayReferences

AWS SES with Supabase Auth: Production-Ready Invite and Password Reset Emails

Published
17 November 2026
Reading time
8 min
Topics
AWS, Supabase, Email

Supabase's built-in mailer is fine while you're building. The moment you invite real customers, you need invite and password reset emails that come from your own domain and land in the inbox. Amazon SES is the obvious choice, and you can plug it in as Supabase's custom SMTP server without writing any SES code.

The setup is small. The hard part is that almost every mistake fails silently. Here's what I set up, and every quiet failure I hit along the way.

The short version

How the pieces fit

  1. Your code calls inviteUserByEmail (from an edge function) or resetPasswordForEmail (from the forgot-password page).
  2. Supabase Auth renders the template, mints the token and hands the message to SES over SMTP.
  3. SES delivers it.
  4. The link brings the person back to your own page, which verifies the token only when they click.

No SES code in your app means nothing to maintain in the send path. It also means nothing of yours logs a failure. Most of the work is proving each layer works, because none of them complains when it doesn't.

SES with AWS CDK

I put the SES resources in one opt-in block of the existing stack. Without an emailIdentity prop, the stack synthesizes exactly as before, so the code can merge before anyone touches DNS.

if (props?.emailIdentity) {
  const configurationSet = new ses.ConfigurationSet(this, "EmailConfigurationSet", {
    configurationSetName: `app-email-${stage}`,
  });

  const identity = new ses.EmailIdentity(this, "EmailIdentity", {
    identity: ses.Identity.domain(props.emailIdentity),
    configurationSet,
  });

  // ...SNS topic for bounces/complaints, IAM SMTP user, outputs
}

It creates a domain identity with DKIM (set to RETAIN, so DNS never points at nothing), a configuration set, an SNS topic for bounces and complaints, an IAM user whose access key becomes the SMTP login (secret in Secrets Manager), and outputs for the DKIM records and SMTP details.

Every name gets a stage suffix, and dev stays in the SES sandbox for good, so a dev deploy can never email a real customer.

Domain identity, and the sandbox

A noreply@ address has no mailbox, so it can't click the verification link an email-address identity needs. A domain identity is verified through DNS and lets you send from any address at the domain.

The identity and the sandbox are separate settings:

New SES accounts start in the sandbox: verified recipients only, 200 emails a day, 1 per second. An invite to a real customer is simply rejected. Request production access in the same region as your identity as soon as you know the launch date. A quota of 200 to 1,000 a day is a credible ask for auth email.

DNS: five records, three silent failures

The three mistakes that never show an error:

Start DMARC at p=none so it only reports. A subdomain like mail.example.com avoids touching the apex, but customers recognise the apex.

SMTP credentials: derive, then test outside Supabase

The SES SMTP password is not your IAM secret key. AWS derives it with a chain of HMAC-SHA256 steps, and the region is one of the inputs. The username is the access key ID.

aws secretsmanager get-secret-value \
  --secret-id app-smtp-prod --region eu-north-1 \
  --query SecretString --output text \
  | npx ts-node scripts/derive-smtp-password.ts --region eu-north-1

Always pass --region. If the script falls back to your laptop's region, SES answers 535 Authentication Credentials Invalid with no hint why.

Then test the credentials before Supabase, with a small script that opens the SMTP session and prints every line. Supabase only reports a generic error.

Supabase custom SMTP

Under Authentication → Emails → SMTP Settings:

Host:          email-smtp.eu-north-1.amazonaws.com
Port:          587 (STARTTLS)
Username:      <SMTP username output>
Password:      <derived password>
Sender email:  noreply@example.com

Two settings that are easy to miss:

The second one bit me. When the redirectTo you send isn't on the list, GoTrue silently falls back to the Site URL. Reset links "work", but land on the home page and the new-password form never appears. The Supabase auth log shows where links really went: on a /recover or /invite request, the referer field is the redirect GoTrue resolved.

The hardest bug. A customer on Microsoft 365 got three invites and two reset emails, and every link said:

403: Email link is invalid or has expired

The cause was Microsoft Defender Safe Links. It opens every link in incoming mail within about a minute of delivery. Supabase's default {{ .ConfirmationURL }} spends the one-time token on a plain GET, so the scanner used up each invite in under a minute, before the person ever clicked. Supabase documents this as "email prefetching", and any Microsoft 365 customer can hit it.

The fix: point the email at your own page, and verify only when the person clicks a button.

<a href="{{ .RedirectTo }}#token_hash={{ .TokenHash }}&type=invite">Accept invitation</a>
// /reset-password: opening the page spends nothing
const onContinue = () =>
  supabase.auth.verifyOtp({ token_hash: tokenHash, type });

Release the page first, then switch the templates. To test it, open the link with curl the way a scanner would, then click it in a browser: the click must still reach the form.

Templates and expiry live in the project, not the repo

GoTrue renders the template stored on the Supabase project. Your invite.html in the repo is only a record. I push both templates with the Management API and let jq do the escaping:

jq -n \
  --rawfile recovery supabase/templates/recovery.html \
  --rawfile invite supabase/templates/invite.html \
  '{mailer_subjects_recovery: "Reset your password",
    mailer_templates_recovery_content: $recovery,
    mailer_subjects_invite: "You are invited",
    mailer_templates_invite_content: $invite}' \
| curl -s -X PATCH "https://api.supabase.com/v1/projects/$PROJECT_REF/config/auth" \
    -H "Authorization: Bearer $SUPABASE_ACCESS_TOKEN" \
    -H "Content-Type: application/json" --data @-

Then read it back and check the template contains {{ .TokenHash }}. Template variables are case-sensitive, and a typo renders as nothing: the email looks fine and the link goes nowhere.

Link expiry is one number for every email type. mailer_otp_exp covers invites and resets together, so 14-day invites mean 14-day reset links too. The dashboard won't go above one day, so set it through the API, and read it back.

Go-live checklist

  1. Request SES production access as soon as you know the launch date.
  2. Deploy the CDK block through CI.
  3. Add DKIM, SPF and DMARC, and check the saved names.
  4. Confirm the identity is verified: aws sesv2 get-email-identity --email-identity example.com
  5. Derive the SMTP password with --region and test it with the SMTP script.
  6. Configure Supabase SMTP and raise the Auth email rate limit.
  7. Add every real origin's /reset-password to the Redirect URLs.
  8. Release the page that verifies on click.
  9. Push the templates, then read them back.
  10. Set mailer_otp_exp through the API, then read it back.
  11. Subscribe someone to the bounce and complaint SNS topic.
  12. Send a real reset, curl it, click it, and check for dkim=pass and spf=pass.

Don't skip step 11. SES throttles or suspends an identity with too many bounces or complaints, and if nobody's subscribed, the first sign is that mail just stops.

What I took away

SES as a pure transport is one of the cheapest upgrades you can make to a Supabase app. Make the click a deliberate action on your own page, and the scanners can open your emails all they want.

References

Previous
Building My Portfolio as a Room
Discuss on LinkedIn ↗