# Web app

> The web app built into your Hub, signing in, installing it as an app, Web Push notifications, and the copy of your mail the Hub keeps while you use it.

Source: https://docs.posternmail.app/apps/web/

The web app is built into the Hub: open your Hub's address in a browser and sign in. This page
covers signing in, installing it as an app, notifications, and the copy of your mail the Hub
keeps for it.

The Hub serves the web app from the same address as its API, for example
`https://mail.example.com`. It always matches the Hub's version, so there is nothing to install
or update. The same web app also runs inside the [desktop app](https://docs.posternmail.app/apps/desktop/).

## Browsers

Use a current version of Chrome, Edge, Firefox or Safari, on a computer or a phone. The web app
is built for modern browsers (ES2022). No list of supported browser versions is published.

Some features need a secure page, that is HTTPS or `http://localhost`:

| Feature | Needs HTTPS |
|---|---|
| Passkeys | Yes, and a host name rather than an IP address. Otherwise the sign-in page offers no passkey button. |
| Web Push (notifications with the tab closed) | Yes |
| Installing as an app, offline start | Yes (the service worker only runs on secure pages) |
| Everything else | No |

See [HTTPS](https://docs.posternmail.app/reach/https/) for the ways to give your Hub a certificate.

## First visit

On a new Hub, the first visit opens the setup: **Set up your Hub**, then **Create the admin
account**, then **Add a mailbox**. The setup may ask for a **Setup code** from the Hub's log
(`postern-hub setup-code` prints it). The [setup guide](https://docs.posternmail.app/setup/) walks through this.

People you invite get a link that opens **Create your account**. See
[Users](https://docs.posternmail.app/admin/users/).

## Signing in

The sign-in page offers whatever your Hub has set up:

| Method | On the page |
|---|---|
| Email and password | **Email**, **Password**, **Sign in** |
| Two-step verification | After the password: "Enter the 6-digit code from your authenticator app", or **Use a recovery code instead** |
| Passkey | **Sign in with a passkey** (HTTPS or `localhost` only) |
| Single sign-on | **Continue with** and the name of your identity provider, when the Hub has OIDC set up |
| A code from another device | **Sign in with a code from another device**: see [Pairing](https://docs.posternmail.app/apps/pairing/#sign-in-a-browser-with-a-code) |

How to set these up is in [Sign-in methods](https://docs.posternmail.app/admin/sign-in/).

If the Hub signed this browser out, the sign-in page says why: "This device was signed out
from another device, and the mail saved on it was removed" or "You were signed out because
your sign-in ended, and the mail saved on this device was removed".

## Install it as an app

The web app is a Progressive Web App. Its manifest names it **Postern**, opens it at the
inbox in its own window, and a service worker keeps the app itself (not your mail) cached, so
it starts even when the Hub doesn't answer.

- **Chrome and Edge (computer):** the install icon at the right of the address bar, or the
  browser menu → **Install Postern**.
- **Safari on a Mac:** **File → Add to Dock**.
- **iPhone and iPad (Safari):** the share button → **Add to Home Screen**.
- **Android (Chrome):** the browser menu → **Add to Home screen** or **Install app**.

The manifest also declares that the app can open `mailto:` links. Browsers that support this
for installed apps may offer it.

> [!TIP]
> On a phone, the [iOS](https://docs.posternmail.app/apps/ios/) or [Android](https://docs.posternmail.app/apps/android/) app is the better choice: it keeps
> its own copy of your mail and works without the Hub.

## Notifications (Web Push)

Open **Settings → Notifications**. Under **This device**, the row **Notifications in this
browser** has a **Turn on** button. The browser then asks for permission; allow it.

| What the row says | Meaning |
|---|---|
| Arrive even when Postern is closed. | Web Push works: the Hub sends notifications straight to your browser, also with the tab closed. |
| Blocked for this site. Allow notifications in your browser's site settings, then turn them on here. | You (or the browser) denied permission. Change it in the browser's site settings. |
| Shown while Postern is open in a tab. Your Hub isn't set up to deliver them when it is closed. | The Hub offers no Web Push key, so notifications only appear while a tab is open. |

- Web Push is encrypted end to end to your browser and does not use the
  [push relay](https://docs.posternmail.app/relay/).
- When a Postern tab is visible, new mail shows as a message inside the app instead of a
  system notification.
- Clicking a notification opens the conversation.
- **Sound** (on by default) and **Turn off** apply to this browser only.
- Which mail notifies you (**All new mail**, **VIPs only**, quiet hours) is synced for all
  devices. See [Notifications](https://docs.posternmail.app/using/notifications/).

## The Hub's copy of your mail

A browser can't connect to mail servers, so the Hub fetches mail for the web app. The apps on
your other devices get mail straight from your providers and don't need this. To save disk
space and work, the Hub keeps a full copy of your mail only while you use the web app:

| Stage | When | What the Hub syncs |
|---|---|---|
| 1. Full copy | From your last use of the web app, for 7 days | All folders, message bodies, search: everything the web app shows. |
| 2. Watching, copy kept | From day 7 until `POSTERN_HUB_MAIL_COPY_DAYS` (default 30) | Only each inbox: headers of the last 7 days, no bodies. Enough for notifications, rules, mute, blocked senders, the Screener, follow-up and snooze. The rest of the copy is kept as it was. |
| 3. Watching, copy dropped | After `POSTERN_HUB_MAIL_COPY_DAYS` | Same as stage 2. Everything outside the recent inbox is deleted from the Hub. |

When you open the web app again, the Hub goes back to stage 1 at once. From stage 2 it catches
up where it stopped. From stage 3 it downloads your mail again, newest first, so older mail
takes a while to appear.

"Using the web app" means reading mail in a browser, or in the desktop app with **Don't keep
mail on this computer**. Signing in a phone or computer through the browser does not count.

### Keep a full copy all the time

Turn on **Settings → Reading & sending → Where your mail is kept → Keep a full copy of my mail
on my Hub** to keep stage 1 for good. Use it if you mainly read mail in the web app and don't
want the first visit after a break to start with a partial mailbox. It applies to your account
only.

### Change how long the copy is kept

`POSTERN_HUB_MAIL_COPY_DAYS` sets how many days after your last web app use the Hub deletes
the copy. It applies to all users of the Hub. The minimum is 1; a value below 7 also shortens
stage 1 to that many days.

| Install | Where to set it |
|---|---|
| Docker Compose | `~/postern/compose.override.yaml`, under `services: hub: environment:`, then `docker compose up -d` |
| Debian, Fedora, Raspberry Pi OS | `/etc/postern/hub.env`, then `sudo systemctl restart postern-hub` |
| Desktop app (built-in Hub) | Not adjustable. The desktop app always uses the web app with its built-in Hub, so the copy stays at stage 1. |

See [Configuration](https://docs.posternmail.app/configuration/) for every variable.

## When the Hub can't be reached

The web app keeps what it has already loaded in the browser (IndexedDB) and keeps the app
itself cached, so it can start and show that mail while the Hub is away.

- A strip says **Can't reach your Hub. Changes are sent when it's back.** (or **You're
  offline.** when the computer has no network). Actions such as archive or mark as read are
  queued and sent when the Hub answers.
- Lists and messages that were never opened in this browser can't be shown.
- If nothing is saved yet, the page says **Can't reach your Hub.** and retries by itself, with
  **Try again now**.

Details are in [Working offline](https://docs.posternmail.app/apps/offline/#the-web-app-when-the-hub-is-down).

## Approving new devices

While you are signed in, the web app shows a prompt when someone uses a code from **Connect a
device** to sign in to your account. Approving a phone or computer from the web app asks for
your password first. See [Pairing a device](https://docs.posternmail.app/apps/pairing/).
