# Ghost

Send a self-hosted Ghost's staff invitations, sign-in codes and members' sign-in links through Sendora's SMTP.

Send the mail that a self-hosted Ghost writes, such as staff invitations, sign-in codes, password resets and members' sign-up and sign-in links, through Sendora's SMTP. This guide is for a Ghost that you run yourself, with Ghost-CLI or Ghost's Docker image.

Ghost emails staff a code when they sign in from a new device, so its mail must work before anyone signs in from another browser. Ghost sends newsletters only through Mailgun, which it sets up apart from this mail, so Sendora cannot send them.

## 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 your site's domain, such as `example.se` for a site at `https://example.se`.
- Access to the machine or the container that runs Ghost, and an administrator's account in Ghost.

## Set up Ghost

1. Add your site's domain under [Domains](https://app.sendora.se/domains), without `www.`, and add the two DNS records it shows, as [Domains](https://sendora.se/docs/domains) explains. Ghost sends members' sign-in links from `noreply@` that domain.
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 Ghost's folder, such as `/var/www/ghost`, replace the `mail` block of `config.production.json` with this one, with the server key as both `user` and `pass`:

```json
{
  "mail": {
    "transport": "SMTP",
    "from": "noreply@example.se",
    "options": {
      "host": "smtp.sendora.se",
      "port": 465,
      "secure": true,
      "auth": {
        "user": "sk_test_…",
        "pass": "sk_test_…"
      }
    }
  }
}
```

Put an address on your verified domain in `from`. Ghost sends its staff mail from it, with your site's title as the sender's name.

Port 465 encrypts the connection from the first byte. Port 587 works too, with `secure` set to `false` and `"requireTLS": true` beside it. Ghost sends through [Nodemailer](https://nodemailer.com/smtp#tls-options), which without `requireTLS` starts TLS only if the server offers it. Someone between Ghost and Sendora who removed that offer would then get the key unencrypted. With `requireTLS`, Ghost fails instead.

If Ghost runs on a host that blocks ports 465 and 587, such as a DigitalOcean Droplet, use port 2525 as you would 587.

4. In Ghost's folder, run `ghost restart`, which reads the file again.
5. In Ghost Admin, open **Settings** › **Staff** and click **Invite people**. Enter an address in **Email address**, and click **Send invitation**.
6. Find the invitation 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 `pass` in place of the test key, and run `ghost restart` again.

## Members' mail

Ghost sends members' sign-up and sign-in links from its support email address, which is `noreply@` your site's domain unless you change it. To send them from another address on a verified domain, open **Settings** › **Signup portal** in Ghost Admin and click **Customize**. On the **Account page** tab, enter the address in **Support email address**, and click **Save**.

## Ghost in Docker

Ghost's Docker image reads the same settings from the container's environment. Name each variable after the setting's place in `config.production.json`, with two underscores between the parts:

```bash
mail__transport=SMTP
mail__from=noreply@example.se
mail__options__host=smtp.sendora.se
mail__options__port=465
mail__options__secure=true
mail__options__auth__user=sk_test_…
mail__options__auth__pass=sk_test_…
```

Then recreate the container, such as with `docker compose up -d`. The variables win over `config.production.json`. For port 587 or 2525, set `mail__options__secure=false` and add `mail__options__requireTLS=true`.

## If a message is refused

When Sendora refuses a message, Ghost logs `Failed to send email. Reason:` with Sendora's reply. `ghost log` shows Ghost's log, and `docker logs` a container's. A password reset shows the same text on the sign-in page. When an invitation fails, the dialog turns **Send invitation** into **Retry**.

`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 Ghost sends a message, click **Check now**.
