# Email delivery Auth emails (GoTrue `hook_send_email`), organization invitations and invoice emails go through the `send_email` queue to the API Worker (`cloudflare_workers/api/triggers/send_email.ts`), which sends them with `sendCloudflareEmail` (`cloudflare_workers/api/email_templates/send.ts`). ## Paths | `AUTH_EMAIL` binding | `SMTP_HOST` | Result | | -------------------- | ----------- | --------------------------------------------------------------------- | | present | any | Cloudflare Email Sending. The SMTP code is never loaded. | | missing | set | SMTP through [worker-mailer](https://github.com/zou-yu/worker-mailer) | | missing | missing | 500 `cloudflare_email_unavailable`; the queue retries | SMTP is only a fallback for installs without the binding (local development, Workers deployed to an account without Email Sending). When the binding exists but fails, the email is not retried over SMTP. ## SMTP settings Set these as Worker variables or secrets. | Variable | Default | Meaning | | ------------------------ | ------------------- | ----------------------------------------------------------------------------------- | | `SMTP_HOST` | none | Turns the SMTP fallback on. | | `SMTP_PORT` | `465` | | | `SMTP_USER`, `SMTP_PASS` | none | Optional. Sent only when `SMTP_USER` is set. | | `SMTP_TLS` | `true` | `true`: TLS from the first byte. `false`: plain SMTP, for local development only. | | `EMAIL_FROM` | `noreply@capgo.app` | Sender on both paths. On the binding path it must be in `allowed_sender_addresses`. | There is no STARTTLS mode. worker-mailer's STARTTLS mode carries on in plaintext, credentials included, when the server does not advertise STARTTLS, so it is never used. Use a server port that speaks TLS from the first byte (usually 465); servers that only offer 587 with STARTTLS are not supported. Cloudflare Workers cannot connect to port 25. The SMTP adapter (`cloudflare_workers/api/email_templates/smtp.ts`) rejects line breaks in the recipient, sender, subject and attachment filenames, because worker-mailer writes them into SMTP commands and headers as given. ## Local development The local Supabase stack runs Mailpit. Enable its SMTP port in `supabase/config.toml` (`[local_smtp] smtp_port`), then run the API Worker with: ```sh SMTP_HOST=127.0.0.1 SMTP_PORT= SMTP_TLS=false ``` Sent emails appear in the Mailpit UI (`[local_smtp] port`). ## Supabase Edge Functions The Supabase `send_email` function (`supabase/functions/_backend/triggers/send_email.ts`) does not send email: it returns 500 `cloudflare_required`. Installs that run only Edge Functions cannot send these emails.