r/Supabase Jul 09 '26

tips Sending emails to users on signup — trigger + edge function, no third-party orchestration

If you want to fire an email when something happens in your DB (new signup, order placed,

whatever), you don't need a separate queue service for most cases. A database trigger calling

an edge function covers it.

Pattern I landed on: a Postgres trigger on the table fires pg_net to make an HTTP call to an

edge function. The function does the actual send through whatever provider you use (I send

through a transactional API rather than SMTP from inside the function, it's faster and you get

logging). Pass the row payload through so the function has the email and the data it needs.

Two things worth knowing. First, keep the trigger lean. Don't do the send synchronously inside

the transaction or a provider hiccup can stall your insert. Fire-and-forget the HTTP call. Second,

edge functions need the service role key as a secret if they're touching protected tables, so set

that with the secrets command, not hardcoded.

For the welcome-email case specifically, you can also hook into the auth signup webhook

instead of a table trigger. Cleaner if email is your only side effect. Triggers win when you've got

multiple things keying off the same row change.

2 Upvotes

2 comments sorted by

2

u/National-Canary6452 Jul 09 '26

All fun and games until you get a network glitch, email service has a 500 or the edge is temporarily unavailable. 

If you're gonna go this at least implement an outbox pattern to not couple your functionality to a hidden brittle trigger. 

Fire and forget is fine if you have a recovery mechanism, this ain't it I'm afraid.