# Alerts

> What raises a rule alert, where you see it, and how to send alerts to ntfy, Discord or Gotify, including servers in your own network.

Source: https://docs.posternmail.app/rules/alerts/

The Hub raises an alert when rule mail needs you: sending was paused, a message could not be
sent or bounced, a mailbox needs you to sign in, or a rule action failed for good. This page
lists the alerts, where they show up, and how to have them sent to ntfy, Discord or Gotify.

## What raises an alert

| Title | Raised when | Message, for example |
|---|---|---|
| Rule mail is paused | A daily limit was reached, or the burst pause started | The rule reached its limit of 100 mails a day |
| | | More than 20 rule mails in a minute: sending from this mailbox is paused for 15 minutes |
| Rule mail needs your attention | A queue item stopped after its retries or was refused | A rule mail needs your attention: 550 5.1.1 user unknown |
| | The Hub cannot tell whether an interrupted send went out | We could not confirm whether a rule mail was sent; it waits for you. |
| | A rule mail bounced | A rule mail bounced: 550 5.1.1 user unknown |
| A mailbox needs you to sign in | Rule mail waits because the provider no longer accepts the sign-in | The mailbox needs to be signed in again; rule mail is waiting. |
| A rule action failed | A **Call a web address** step failed after all retries | A rule's webhook could not be delivered to hooks.example.com: HTTP 500 |

See [Limits and guards](https://docs.posternmail.app/rules/limits/) and [Sending queue](https://docs.posternmail.app/rules/sending-queue/) for the causes.

## Where you see alerts

- **In the app**: open alerts are listed at the top of **Settings → Rules** under **Needs your
  attention**, with a link to the place to fix it (**Open the sending queue** or **Open
  mailboxes**) and **Dismiss**.
- **On your devices**: each new alert sends one notification to your signed-in devices, with the
  alert's title and message.
- **In your alert channels**: ntfy, Discord or Gotify, if you set them up below.

The same problem does not raise a new alert again and again. While an alert is open, a repeat of
the same condition (same kind, same mailbox, same rule; for sign-in and the burst pause, same
mailbox) only counts up: the message ends in "(3 times)". Your devices and channels are told
once, when the alert is created. After you **Dismiss** it, the next occurrence raises a new
alert. Dismissed alerts are kept for 30 days. The list shows at most 200 alerts.

## Alert channels

Set channels up under **Settings → Notifications → Alerts about rules**. The section says "Get a
message elsewhere when rule mail needs you: sending was paused, a message couldn't be sent, or a
mailbox needs you to sign in." You can turn on one, two or all three.

The same channels also receive **Send a notification** steps that have **Also send it to your
alert channels** ticked (see [Steps](https://docs.posternmail.app/rules/steps/#send-a-notification)).

Tokens and webhook addresses are stored encrypted on the Hub and never shown again. A field with
a saved secret says "Saved. Type to replace it."; type a new value to replace it, or choose
**Remove it** and **Save** to delete it.

### ntfy

[ntfy](https://ntfy.sh) delivers push messages to its phone and desktop apps. You can use the
public server `ntfy.sh` or your own.

1. In the ntfy app, subscribe to a topic with a name that is hard to guess, for example
   `postern-alerts-7f3k9q`. On `ntfy.sh`, anyone who knows the topic name can read it.
2. In Postern, open **Settings → Notifications** and turn on **Send alerts to ntfy** under
   **Alerts about rules**.
3. **Server**: leave it empty for `https://ntfy.sh`, or type your own server, for example
   `https://ntfy.example.com`.
4. **Topic**: the topic from step 1. Up to 64 letters, digits, `-` and `_`.
5. **Access token (optional)**: only if your server needs one (an ntfy access token, `tk_...`).
6. Choose **Save**, then **Send test**.

> **Check:** the ntfy app shows "Postern test" with "This channel works. Alerts about your rules
> will arrive here." Postern says "Test sent to ntfy. Check that it arrived."

> **If it did not work:** the message "The test didn't arrive." gives the reason. "Use up to 64
> letters, digits, - and _" means the topic has other characters. An HTTP 401 or 403 means the
> server needs a token or the token has no write access to the topic. For a server in your own
> network, see [Servers in your own network](https://docs.posternmail.app/rules/alerts/#servers-in-your-own-network).

Alerts arrive with high priority and a warning tag; notifications from **Send a notification**
steps with default priority.

### Discord

1. In Discord, open the channel's settings → **Integrations** → **Webhooks** → **New
   Webhook**, then **Copy Webhook URL**.
2. In Postern, turn on **Send alerts to Discord** under **Alerts about rules**.
3. Paste the address into **Webhook address**. It looks like
   `https://discord.com/api/webhooks/123456789012345678/abc...`.
4. Choose **Save**, then **Send test**.

> **Check:** a message from "Postern" with the title "Postern test" appears in the channel.

> **If it did not work:** "Paste the webhook address from Discord" means the address is not a
> Discord webhook address (it must start with `https://discord.com/api/webhooks/`; the
> `discordapp.com`, `ptb.` and `canary.` variants work too). "Add the webhook address first."
> means the field is empty. An HTTP 404 means the webhook was deleted in Discord: create a new
> one.

Alerts appear as an embed in orange, notifications in blue.

### Gotify

[Gotify](https://gotify.net) is a push server you run yourself.

1. In Gotify, go to **Apps** → **Create application**, name it `Postern` and copy its token.
2. In Postern, turn on **Send alerts to Gotify** under **Alerts about rules**.
3. **Server**: your Gotify address, for example `https://gotify.example.com`.
4. **App token**: the token from step 1.
5. Choose **Save**, then **Send test**.

> **Check:** the Gotify app shows "Postern test".

> **If it did not work:** "Add the server and an app token first." means a field is empty. An
> HTTP 401 means the token is wrong. "This Hub doesn't send to addresses in a local network (the
> admin can allow it)" means your Gotify server has a private address: see the next section.

Alerts are sent with priority 7, notifications with priority 4.

### What a channel receives

| | ntfy | Discord | Gotify |
|---|---|---|---|
| Request | `POST <server>/<topic>`, the message as plain text | `POST` to the webhook, JSON | `POST <server>/message`, JSON |
| Title | `Title` header | Embed title | `title` |
| Message | Body | Embed description (up to 4,000 characters) | `message` |
| Sign-in | `Authorization: Bearer <token>` if set | Part of the webhook address | `X-Gotify-Key` header |

The title is the alert's title ("Rule mail is paused"); for **Send a notification** steps it is
"Postern". A delivery that fails is tried again after 1 minute, 5 minutes, 30 minutes, 2 hours
and 6 hours, then dropped and written to the Hub's log. **Send test** works even when the channel
is turned off, so you can check it before you turn it on.

## Servers in your own network

By default the Hub only sends alerts (and [webhooks](https://docs.posternmail.app/rules/webhooks/)) to public internet
addresses. A server with a private address, such as `http://192.168.1.20:8080` for Gotify on
your LAN, is refused with "This Hub doesn't send to addresses in a local network (the admin can
allow it)". This protects your network from a rule or user that points the Hub at internal
services.

To allow private networks (`10.0.0.0/8`, `172.16.0.0/12`, `192.168.0.0/16`, `100.64.0.0/10`
for Tailscale, and `fc00::/7`), set `POSTERN_RULES_ALLOW_LAN=1` for the Hub. Loopback
(`127.0.0.1`, `localhost`) and link-local addresses stay blocked in any case. The setting
applies to all users of the Hub.

**Docker Compose:**
`compose.yaml` does not pass this variable through, so add it in
`~/postern/compose.override.yaml` (create the file if it does not exist):

```yaml
services:
  hub:
    environment:
      POSTERN_RULES_ALLOW_LAN: "1"
```

Then apply it:

```sh
cd ~/postern && docker compose up -d
```

> **Check:** `docker compose exec hub env` lists `POSTERN_RULES_ALLOW_LAN=1`, and **Send test**
> on the channel reaches your server.

> **If it did not work:** run `docker compose config` and look for the variable under `hub`. If
> it is missing, the override file is not next to `compose.yaml` or its indentation is wrong.
**Debian and Ubuntu, Fedora and RHEL and Raspberry Pi OS:**
Add the line to `/etc/postern/hub.env`:

```sh
echo 'POSTERN_RULES_ALLOW_LAN=1' | sudo tee -a /etc/postern/hub.env
```

Then restart the Hub:

```sh
sudo systemctl restart postern-hub
```

> **Check:** **Send test** on the channel reaches your server.

> **If it did not work:** check the file with `sudo cat /etc/postern/hub.env` (one variable per
> line, no spaces around `=`), and the log with `sudo journalctl -u postern-hub -n 50`.
**Desktop app (built-in Hub):**
The built-in Hub inherits the environment of the desktop app. To allow private networks, quit
the app and start it from a terminal with the variable set. On macOS:

```sh
POSTERN_RULES_ALLOW_LAN=1 /Applications/Postern.app/Contents/MacOS/Postern
```

On Linux and Windows, set the variable the same way before you start the app. The setting
lasts until the app is quit.

> **Check:** **Send test** on the channel reaches your server.

> **If it did not work:** quit the app completely (on macOS with **Postern → Quit**, not only
> by closing the window) and start it again from the terminal.

> [!NOTE]
> Without the setting, the Hub also refuses host names ending in `.local`, `.internal`, `.lan`
> and `.home.arpa`, and names without a dot. With it, such names are allowed, and the address
> they resolve to is checked like any other. `localhost` and names ending in `.localhost` are
> always refused.
