# Nextcloud

Send Nextcloud's password resets, share notifications and other mail through Sendora's SMTP.

Send the mail that Nextcloud writes, such as password resets, share notifications and welcome emails to new accounts, through Sendora's SMTP.

## 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 Nextcloud's mail comes from.
- A Nextcloud administrator's account with an email address under **Personal settings** › **Profile & contact**. Nextcloud sends its test email to that address.

## Set up Nextcloud

1. Add the domain that Nextcloud'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 Nextcloud, open **Administration settings** › **Basic settings**, and find **Email server**. Enter Sendora's values:

| Field                                       | Value                                                                                  |
| ------------------------------------------- | -------------------------------------------------------------------------------------- |
| Send mode                                   | **SMTP**                                                                               |
| Encryption                                  | **SSL/TLS**                                                                            |
| Disable certificate verification (insecure) | Off                                                                                    |
| From address                                | `no-reply` in **Email**, and your verified domain, such as `example.se`, in **Domain** |
| Server address                              | `smtp.sendora.se` in **Host**, and `465` in **Port**                                   |
| Authentication required                     | On                                                                                     |
| Login                                       | The server key                                                                         |
| Password                                    | The server key                                                                         |

Port 465 encrypts the connection from the first byte. Port 587 works too, with **Encryption** set to **None / STARTTLS**. Nextcloud then starts TLS only if the server offers it. [Lines 277 to 279 of its mail code](https://github.com/nextcloud/server/blob/v35.0.3/lib/private/Mail/Mailer.php#L277-L279) say so in 35.0.3. If someone between Nextcloud and Sendora removed that offer, Nextcloud would send the key unencrypted, so use 465 where you can. If Nextcloud runs on a host that blocks ports 465 and 587, such as a DigitalOcean Droplet, use port 2525 as you would 587.

4. Click **Save settings**.
5. Click **Send test email**. Nextcloud sends it to your own address, and shows **Email sent successfully**.
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 **Login** and **Password** in place of the test key, and click **Save settings**.

## Nextcloud in Docker

The `nextcloud` Docker image can take the same settings from the container's environment. Set these variables, with the server key as both `SMTP_NAME` and `SMTP_PASSWORD`, and your verified domain in `MAIL_DOMAIN`:

```bash
SMTP_HOST=smtp.sendora.se
SMTP_SECURE=ssl
SMTP_PORT=465
SMTP_NAME=sk_test_…
SMTP_PASSWORD=sk_test_…
MAIL_FROM_ADDRESS=no-reply
MAIL_DOMAIN=example.se
```

Then recreate the container, such as with `docker compose up -d`. While the variables are set, their values win over the ones on **Basic settings**. For port 587 or 2525, set `SMTP_SECURE=tls`, which starts TLS as **None / STARTTLS** does.

## If a message is refused

When Sendora refuses the test email, Nextcloud shows **A problem occurred while sending the email**. Nextcloud's log, under **Administration settings** › **Logging**, holds Sendora's reply for the test email and for the rest of Nextcloud's mail. `535 5.7.8` means the key is wrong or revoked. `550 5.7.1` means the From 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 Nextcloud sends a message, click **Check now**.
