AWS SES with Supabase Auth: Production-Ready Invite and Password Reset Emails
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
- Keep Supabase Auth in charge. It owns templates, one-time tokens and expiry. SES only delivers.
- Use a domain identity if you send from
noreply@. - Leave the SES sandbox early. Production access takes days.
- Get DNS right. Three of the mistakes there never show an error.
- Derive the SMTP password per region and test it outside Supabase.
- Verify tokens on click, not on page load, or email scanners spend them first.
- Read every setting back after you change it.
How the pieces fit
- Your code calls
inviteUserByEmail(from an edge function) orresetPasswordForEmail(from the forgot-password page). - Supabase Auth renders the template, mints the token and hands the message to SES over SMTP.
- SES delivers it.
- 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:
- The identity controls who you send from.
- The sandbox controls who you send to.
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
- CNAME × 3:
<token>._domainkey→<token>.dkim.amazonses.com - TXT at the apex:
v=spf1 include:_spf.google.com include:amazonses.com ~all - TXT at
_dmarc:v=DMARC1; p=none; rua=mailto:<an inbox you read>
The three mistakes that never show an error:
- SPF must cover your existing mail provider too. If staff mail goes through Google Workspace, an SPF record listing only SES makes every staff email fail SPF. Include both, and use
~all, not-all. - Add SPF to the existing TXT record set. In Route 53, a second TXT set at the apex replaces the first, and your
google-site-verificationstring disappears with it. - Route 53 appends the zone name. Enter
xyz123._domainkey, not the full name SES shows, or you get…example.com.example.com. Check the saved record, not what you typed.
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.
535 Authentication Credentials Invalid: wrong password, or the wrong region.554 Email address is not verified: still in the sandbox.250 Ok: SES is fine. Any later failure is in the Supabase config.
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:
- Raise the Auth email rate limit. It's separate from your SES quota and throttles you long before SES would.
- Add every real origin to the Redirect URLs list, with the
/reset-passwordpath.
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.
Link scanners spend your one-time tokens
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 });
- Verify on click, not on page load. The scanner runs JavaScript, so a
useEffectstill loses the race. I added a unit test that opening the page never callsverifyOtp. - Put the token after
#, not?. The fragment never reaches a server, so the token stays out of your host's logs. - Keep accepting old-style links until the emails already sent expire.
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
- Request SES production access as soon as you know the launch date.
- Deploy the CDK block through CI.
- Add DKIM, SPF and DMARC, and check the saved names.
- Confirm the identity is verified:
aws sesv2 get-email-identity --email-identity example.com - Derive the SMTP password with
--regionand test it with the SMTP script. - Configure Supabase SMTP and raise the Auth email rate limit.
- Add every real origin's
/reset-passwordto the Redirect URLs. - Release the page that verifies on click.
- Push the templates, then read them back.
- Set
mailer_otp_expthrough the API, then read it back. - Subscribe someone to the bounce and complaint SNS topic.
- Send a real reset,
curlit, click it, and check fordkim=passandspf=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
- A delivered email is not proof the link works. I had a 200 from
/recover, a fresh token and no SMTP error, and the email still had no link, because the stored template had lost its anchor. - Read a setting back after you change it. A request that "succeeded" proves nothing until the stored value says so.
- Test each layer on its own: the SMTP script for SES,
curlplus a click for the link, the auth log for redirects. - Assume the recipient's mail system clicks first. Any link that changes state on a GET will be spent by a scanner.
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.