Emails
How Listoca's emails leave the server, and how to set up Resend, the provider that sends them in production.
Every email is a React Email template in packages/mail/src/templates, translated through the
mail i18n scope. In production Resend sends them. Locally they land in
Mailpit at http://localhost:3044 and nothing leaves your machine.
How an email is sent
| Sent by | |
|---|---|
| auth emails | send-email, right away, when Supabase Auth calls the send-email hook |
| every other email | send-queued-email, within a minute, from a row in email_outbox |
In production Auth sends only the email change confirmation; locally it also sends the sign-in
code and link. Everything else (invitations, notifications, the daily summary, billing, the
contact form, the newsletter confirmation) is queued with private.enqueue_email(...).
send-queued-email retries a failed send up to five times with a growing delay and keeps the
error in the row's last_error (Scheduled work). Both functions go
through createMailer (packages/mail/src/send-email.tsx), which hands the rendered email to the
provider named by MAIL_PROVIDER.
Adding or changing a template: the add-or-edit-an-email skill. bun run dev:mail previews
every template at http://localhost:3023.
Providers
| Where | MAIL_PROVIDER | Set in |
|---|---|---|
| production | resend | deploy/supabase/functions.env.example, or Coolify step 6 |
| local | mailpit | supabase/config.toml ([edge_runtime.secrets]) |
| unit tests | console | packages/functions/src/testing.ts |
packages/mail also has smtp and postmark providers. Listoca doesn't use them; switching
is MAIL_PROVIDER and that provider's key (packages/functions/src/env.ts).
Setting up Resend
-
Add the domain. In Resend's dashboard, Domains → Add Domain, with the domain of the address you send from (
hello@example.comsends fromexample.com). Pick the region there; the privacy policy names it. -
DNS records. Add the DKIM and SPF records Resend shows at your DNS host, and wait until the domain shows as verified. Add a DMARC record yourself (a
TXTon_dmarc); start withv=DMARC1; p=none;and tighten it once the reports look clean. -
API key. API Keys → Create API Key. With
NEWSLETTER_PROVIDER=resendthe same key also adds newsletter contacts, which takes Full access. Without the newsletter, Sending access limited to the domain is enough. -
The functions' settings, in
/opt/supabase/functions.env(fromdeploy/supabase/functions.env.example) or in Coolify's variables:MAIL_PROVIDER=resend MAIL_FROM=Listoca <hello@example.com> RESEND_API_KEY=CHANGE_MEMAIL_FROMmust be on the verified domain, or Resend refuses every email. The functions read the file when their container starts:docker compose up -din/opt/supabaseafter a change, or redeploy in Coolify. -
Send one. Submit the marketing site's contact form: it queues an email to
CONTACT_EMAIL. Within a minute it shows in Resend's Emails log. If it doesn't, look at the row inemail_outbox:last_errorholds Resend's answer.
The privacy policy names the email provider ([EMAIL PROVIDER] and [EMAIL PROVIDER COUNTRY]
in apps/marketing/content/legal/privacy.*.mdx): put in Resend and the region from step 1.
Newsletter
NEWSLETTER_PROVIDER=resend adds a confirmed sign-up as a Resend contact, with the same
RESEND_API_KEY. RESEND_NEWSLETTER_SEGMENT_ID puts new contacts in a segment, the one you send
broadcasts to. The double opt-in and the forms: Marketing site.