Clean-room Rust rewrite (written without reference to useSend source). Crates: mail-types, mail-core, mail-server, mail-auth, mail-submit, mail-hooks, mail-deliverability; sdks/ts (@scribase/mail); docs/. Each verified by running locally (see plans/scribase-mail-rust-2026-11-12.md). mail-mta, mail-inbound, mail-oci are still in progress and not in this commit. Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com>
126 lines
5.2 KiB
Markdown
126 lines
5.2 KiB
Markdown
# Send Supabase Auth emails through Scribase Mail
|
|
|
|
Supabase's built-in mailer is limited to a few emails per hour and sends from
|
|
`noreply@mail.app.supabase.io`. Two ways to send your sign-up, magic-link,
|
|
password-reset and invite emails from your own domain through Scribase Mail:
|
|
|
|
- **Option A: SMTP.** Five fields in the Supabase dashboard. Supabase keeps
|
|
rendering its own templates; we deliver them.
|
|
- **Option B: Send Email Hook.** Supabase calls our HTTPS endpoint; we render
|
|
clean templates (or yours) and deliver. Needed if you want our templates,
|
|
per-type customisation, or to see every auth email in the Scribase log with
|
|
its `email_action_type`.
|
|
|
|
Both need a verified domain and an API key first.
|
|
|
|
## 0. One-time setup in Scribase Mail
|
|
|
|
1. Add your domain: `POST /domains {"name": "example.com"}` (or the dashboard).
|
|
Publish the three DNS records it returns, then `POST /domains/{id}/verify`.
|
|
2. Create an API key: `POST /api-keys {"name": "supabase", "permission": "sending_access", "domain_id": "<id>"}`.
|
|
Copy the `sk_...` token; it is shown once.
|
|
|
|
## Option A: SMTP settings
|
|
|
|
1. Supabase Dashboard → **Authentication** → **Emails** → **SMTP Settings**
|
|
(direct link: `https://supabase.com/dashboard/project/_/auth/smtp`).
|
|
2. Turn on **Enable Custom SMTP** and fill in:
|
|
|
|
| Field | Value |
|
|
|---|---|
|
|
| Sender email | `auth@example.com` (must be on your verified domain) |
|
|
| Sender name | your app's name |
|
|
| Host | `mail.scribase.com` |
|
|
| Port number | `587` (or `465`) |
|
|
| Username | `scribase` |
|
|
| Password | your `sk_...` API key |
|
|
| Minimum interval between emails | `1` second is fine |
|
|
|
|
3. Save. Supabase lowers its auth email rate limit to 30/hour when custom
|
|
SMTP is enabled; raise it under **Authentication → Rate Limits**.
|
|
4. Test with a magic link from your app. The email appears in `GET /emails`
|
|
tagged `source=smtp`, DKIM-signed for your domain.
|
|
|
|
Via the Management API instead of the dashboard:
|
|
|
|
```sh
|
|
curl -X PATCH "https://api.supabase.com/v1/projects/$PROJECT_REF/config/auth" \
|
|
-H "Authorization: Bearer $SUPABASE_ACCESS_TOKEN" -H "Content-Type: application/json" \
|
|
-d '{"external_email_enabled": true, "smtp_admin_email": "auth@example.com",
|
|
"smtp_sender_name": "Example", "smtp_host": "mail.scribase.com", "smtp_port": "587",
|
|
"smtp_user": "scribase", "smtp_pass": "sk_...", "smtp_max_frequency": 1}'
|
|
```
|
|
|
|
## Option B: Send Email Hook
|
|
|
|
1. Create a hook project in Scribase Mail (needs a full-access key):
|
|
|
|
```sh
|
|
curl -X POST https://mail.scribase.com/hooks/projects \
|
|
-H "Authorization: Bearer sk_..." -H "Content-Type: application/json" \
|
|
-d '{"name": "Example", "slug": "example", "app_name": "Example",
|
|
"from": "Example <auth@example.com>"}'
|
|
```
|
|
|
|
The response contains `hook_secret` (`v1,whsec_...`) and `endpoint_path`
|
|
(`/hooks/supabase/example`). If Supabase already generated a secret for
|
|
you, pass it as `hook_secret` instead and we will use that one.
|
|
|
|
2. Supabase Dashboard → **Authentication** → **Hooks** → **Add hook** →
|
|
**Send Email**. Choose **HTTPS**, enter
|
|
`https://mail.scribase.com/hooks/supabase/example` and the secret
|
|
(`v1,whsec_...`). Enable the hook.
|
|
|
|
Via `supabase/config.toml` for local development:
|
|
|
|
```toml
|
|
[auth.hook.send_email]
|
|
enabled = true
|
|
uri = "https://mail.scribase.com/hooks/supabase/example"
|
|
secrets = "env(SEND_EMAIL_HOOK_SECRET)"
|
|
```
|
|
|
|
3. Test with a sign-up or magic link. The user receives a Scribase-rendered
|
|
email whose button points at
|
|
`{site_url}/auth/v1/verify?token=...&type=magiclink&redirect_to=...`.
|
|
`GET /hooks/projects/{id}/deliveries` lists every call with the email ids;
|
|
`GET /emails/{id}` shows the message.
|
|
|
|
### Customising the copy
|
|
|
|
Set `templates` on the project (create or `PATCH /hooks/projects/{id}`):
|
|
|
|
```json
|
|
{
|
|
"templates": {
|
|
"magiclink": {
|
|
"subject": "Your {{app_name}} sign-in link",
|
|
"html": "<p>Hi {{email}},</p><p><a href=\"{{confirmation_url}}\">Sign in</a></p><p>Or use code {{token}}.</p>",
|
|
"text": "Sign in: {{confirmation_url}}\nOr use code {{token}}."
|
|
}
|
|
}
|
|
}
|
|
```
|
|
|
|
Variables: `confirmation_url`, `token`, `token_hash`, `new_token`, `email`,
|
|
`new_email`, `old_email`, `site_url`, `redirect_to`, `app_name`,
|
|
`email_action_type`. Supabase's own names (`{{ .ConfirmationURL }}`,
|
|
`{{ .Token }}`, `{{ .SiteURL }}`, `{{ .Email }}`, `{{ .RedirectTo }}`) also
|
|
work, so you can paste your existing Supabase templates. Any field you leave
|
|
out falls back to the built-in copy. Preview without sending:
|
|
`GET /hooks/projects/{id}/preview/magiclink`.
|
|
|
|
Action types covered: `signup`, `invite`, `magiclink`, `recovery`,
|
|
`email_change` (both addresses when Secure Email Change is on),
|
|
`reauthentication`, `email`, and the `*_notification` types.
|
|
|
|
### Troubleshooting
|
|
|
|
- `401 webhook signature does not match`: the secret in Supabase and on the
|
|
project differ. `PATCH /hooks/projects/{id} {"hook_secret": "v1,whsec_..."}`.
|
|
- `401 webhook-timestamp is outside the allowed window`: clock skew over 5
|
|
minutes, or a replayed request.
|
|
- `422 the project's from domain is not verified`: finish step 0.
|
|
- Supabase shows the error message from our JSON body in its logs
|
|
(**Authentication → Logs**).
|