# Gitea

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

Send the mail that Gitea writes, such as notifications of issues and pull requests, password resets and requests to confirm an address, 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 Gitea's mail comes from.
- Access to Gitea's configuration file, `app.ini`, and a Gitea administrator's account.

## Set up Gitea

1. Add the domain that Gitea'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. Add these lines to `app.ini`, with the server key as both `USER` and `PASSWD`. In Gitea, **Site Administration** › **Configuration** › **Summary** shows where the file is, under **Configuration File Path**.

```ini
[mailer]
ENABLED = true
PROTOCOL = smtps
SMTP_ADDR = smtp.sendora.se
SMTP_PORT = 465
USER = sk_test_…
PASSWD = sk_test_…
FROM = Gitea <gitea@example.se>
```

Put an address on your verified domain in `FROM`. To email its users about issues, pull requests and comments, Gitea also needs `ENABLE_NOTIFY_MAIL = true` under `[service]`.

Port 465 encrypts the connection from the first byte. Port 587 works too, with `PROTOCOL = smtp+starttls`. Gitea then starts TLS only if the server offers it. [Line 96 of its mail code](https://github.com/go-gitea/gitea/blob/v28.4.0/services/mailer/sender/smtp.go#L96) shows this in 28.4.0. If someone between Gitea and Sendora removed that offer, Gitea would send the key unencrypted, so use 465 where you can.

If Gitea runs on a host that blocks ports 465 and 587, such as a DigitalOcean Droplet, use port 2525 with `PROTOCOL = smtp+starttls`. Without `PROTOCOL`, Gitea would take 2525 for a port that encrypts from the first byte, and fail.

4. Restart Gitea, which reads `app.ini` only when it starts.
5. Open **Site Administration** from your user menu, then **Configuration** › **Summary**. Under **Mailer Configuration**, enter your address in **Send Testing Email**, and click **Send**.
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 `USER` and `PASSWD` in place of the test key, and restart Gitea.

## Gitea in Docker

Gitea's Docker image keeps `app.ini` at `/data/gitea/conf/app.ini`, in the volume it mounts at `/data`. Edit the file there, and restart the container. You can also set each line as a variable in the container's environment, named `GITEA__mailer__` followed by the key, such as `GITEA__mailer__SMTP_ADDR=smtp.sendora.se`. Then recreate the container. The image writes the variables into `app.ini` when it starts.

## If a message is refused

When Sendora refuses the testing email, Gitea shows **Failed to send a testing email**, followed by Sendora's reply. Gitea sends the rest of its mail in the background, and its log holds `Failed to send emails` with Sendora's reply. `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 Gitea sends a message, click **Check now**.
