# Supabase Auth

Send Supabase Auth's sign-up confirmations, magic links and password resets through Sendora's SMTP.

Send the mail that Supabase Auth writes, such as sign-up confirmations, magic links and password resets, through Sendora's SMTP. Supabase's built-in email service sends only to your organisation's team members, so it is for trying Auth out.

## Before you start

- A Sendora account. A test server works from the moment the account exists. A live server sends once your account is approved. The account starts on Free, within the [limits](https://sendora.se/docs/limits#the-free-tier) that [Account › Usage](https://app.sendora.se/account/usage) in the dashboard shows.
- Access to the DNS of the domain that Supabase's mail comes from.
- Access to your project's settings in Supabase's dashboard.

## Set up Supabase Auth

1. Add the domain that Supabase's mail comes from under [Domains](https://app.sendora.se/domains), and add the two DNS records it shows, as [Domains](https://sendora.se/docs/domains) explains.
2. Create a test server under [Servers › New server](https://app.sendora.se/servers/new), with **Testserver** ticked, and create a key on its **API keys** tab. The key starts with `sk_test_`. A [test server](https://sendora.se/docs/test-servers) takes mail as a live server does and delivers none of it.
3. In Supabase's dashboard, open **Authentication**, then **Emails** and its **SMTP Settings** tab. Switch on **Enable custom SMTP**, and enter Sendora's values:

| Field                | Value                                                             |
| -------------------- | ----------------------------------------------------------------- |
| Sender email address | An address on your verified domain, such as `no-reply@example.se` |
| Sender name          | The name your users see, such as your app's                       |
| Host                 | `smtp.sendora.se`                                                 |
| Port number          | `465`                                                             |
| Username             | The server key                                                    |
| Password             | The server key                                                    |

4. Click **Save changes**.
5. Send a message from the project, such as a sign-up from your app. Or invite someone under **Authentication** › **Users**, with **Add user** and then **Send invitation**. A test server delivers nothing, so nobody receives the message.
6. Find the message on the server's **Messages** tab under [Servers](https://app.sendora.se/servers).
7. Once your account is approved, create a key on your live server's **API keys** tab, such as the default server that signup made. Put it in **Username** and **Password** in place of the test key, and click **Save changes**.

## Raise Supabase's email limit

Supabase limits how many emails a project sends an hour, and sets the limit to 30 when you switch on custom SMTP. To send more, raise **Rate limit for sending emails** under **Authentication** › **Rate Limits**. Sendora's own [limits](https://sendora.se/docs/limits) apply as well.

## Self-hosted Supabase

A self-hosted Supabase takes the same values from the `.env` file beside its `docker-compose.yml`. Use the server key as both user and password:

```bash
SMTP_ADMIN_EMAIL=no-reply@example.se
SMTP_SENDER_NAME=Example
SMTP_HOST=smtp.sendora.se
SMTP_PORT=465
SMTP_USER=sk_test_…
SMTP_PASS=sk_test_…
```

Then run `docker compose up -d`, which restarts Auth with the new values. If Supabase runs on a host that blocks ports 465 and 587, such as a DigitalOcean Droplet, set `SMTP_PORT=2525`. Supabase Auth then encrypts the connection with STARTTLS before it signs in.

## If a message is refused

Supabase answers the request with a `500` error, such as `Error sending confirmation email`, and its Auth logs hold Sendora's reply. `535 5.7.8` means the key is wrong or revoked. `550 5.7.1` means the sender's domain is not verified, or that a live server's account is not yet approved. `451 4.7.0` means that a limit is reached, such as Free's [daily limit](https://sendora.se/docs/limits#the-free-tier). `550 5.1.1` means the recipient's address is on the [suppression list](https://sendora.se/docs/suppressions), for example after a hard bounce. [SMTP replies](https://sendora.se/docs/smtp#smtp-replies) lists every reply.

## Test the setup

On the server's **API keys** tab under [Servers](https://app.sendora.se/servers), **Test the setup** shows each valid key's latest sign-in and accepted message over SMTP. It also shows the key's latest refusals, each with what to do. After Supabase Auth sends a message, click **Check now**.
