# Connect over JMAP

> Connect a mailbox over JMAP with an API token, what works, which servers, and the current limits of JMAP support.

Source: https://docs.posternmail.app/providers/jmap/

JMAP is a modern mail protocol (RFC 8620 and RFC 8621) that replaces IMAP and SMTP with one
HTTPS API and pushes every change to the client at once. Postern can use it instead of IMAP.
This page explains what works, how to connect and what to expect.

> [!IMPORTANT]
> JMAP support is **less tested** than Gmail, Microsoft and IMAP. It is used with Fastmail. If a
> JMAP mailbox misbehaves, connecting the same account over [IMAP](https://docs.posternmail.app/providers/imap/) is the proven
> fallback.

## Which servers

| Server | How to connect |
|---|---|
| **Fastmail** | In the app. The Hub recognizes Fastmail and offers **Use an API token**. See [Fastmail](https://docs.posternmail.app/providers/fastmail/). |
| Other JMAP servers (for example Stalwart or Cyrus) | Through the Hub's API only, see [Other JMAP servers](https://docs.posternmail.app/providers/jmap/#other-jmap-servers). The add dialog offers JMAP only for Fastmail. |

## What you need

- The server's **JMAP session URL**, for example `https://api.fastmail.com/jmap/session`. It
  must use `https://`.
- A **token** the server accepts as a Bearer token (`Authorization: Bearer …`), with access to
  read and change mail and to send. Postern does not connect to JMAP with a username and
  password.

## Connect Fastmail over JMAP

The short version (details on the [Fastmail page](https://docs.posternmail.app/providers/fastmail/#option-a-api-token-jmap)):

### 1. Create a token

In Fastmail, **Settings → Privacy & Security → Integrations → API tokens → New API token**, with
access to **Email** (not read-only) and **Email submission**.

> **Check:** you have copied a token that starts with `fmu1-`.

> **If it did not work:** see the [Fastmail page](https://docs.posternmail.app/providers/fastmail/).

### 2. Add the mailbox

**Settings → Mailboxes → Add mailbox → Other**, type the address, **Continue**, **Use an API
token**. Paste the token into **API token**. **Server address** opens the field **Server address
(JMAP session URL)**, already filled in. Click **Connect**.

The Hub fetches the session and lists the folders once before it saves anything.

> **Check:** the dialog shows **you@fastmail.com is connected**.

> **If it did not work:** **The sign-in was rejected** means the server refused the token.
> **The mail server didn't answer** means the session URL is wrong or unreachable.

## Other JMAP servers

The add dialog only offers the token for Fastmail. For another JMAP server, add the mailbox with
the Hub's API: `POST /api/v1/mailboxes` with this body (see the [API reference](https://docs.posternmail.app/reference/api/)
for signing in to the API):

```json
{
  "kind": "jmap",
  "email": "you@example.com",
  "displayName": "Your Name",
  "sessionUrl": "https://mail.example.com/.well-known/jmap",
  "token": "your-token"
}
```

The Hub checks the session and the token first and answers with the new mailbox, or with an
error:

| Answer | Meaning |
|---|---|
| "A https sessionUrl and token are required" | The URL is not `https://` or the token is empty. |
| "The server rejected the sign-in. …" (`auth_failed`) | The server refused the token. |
| "Couldn't connect to mail.example.com: …" (`provider_error`) | The session URL could not be fetched or the server answered with an error. |
| "This mailbox is already connected. Update its credentials instead." | The address is already connected over JMAP. |

Once added, the mailbox appears in every app like any other, and **Update sign-in** in
**Settings → Mailboxes** asks for a new token.

## What the Hub does over JMAP

- **Session.** The Hub reads the session once and caches it (API, upload, download and push
  addresses, the mail account, the server's limits). It reads it again when the server says it
  changed.
- **Folders** are the server's mailboxes, and a message can be in several (like Gmail labels).
  Inbox, Sent, Drafts, Archive, Trash and Spam are found by their roles. Archive, Trash and Spam
  are created when missing.
- **States.** Read, flagged, answered and draft come from the `$seen`, `$flagged`, `$answered`
  and `$draft` keywords. Your tags are saved as keywords. Marking as spam sets `$junk`, marking
  as not spam sets `$notjunk`.
- **First download.** Newest first, page by page, with progress. Changes made meanwhile are
  picked up.
- **New mail and changes** arrive through the server's push stream (JMAP EventSource), for all
  folders. A stream silent for three minutes is reopened. The Hub also checks every 5 minutes.
- **Sending.** The message is uploaded, stored in Drafts, submitted, then moved to Sent by the
  server. The sending identity is the one matching your From address: the exact address, then a
  `*@domain` identity, then the first identity of the account. If submission fails, the draft is
  removed again.
- **Threads** come from the server's thread IDs.
- **Devices.** The desktop and mobile apps connect to the JMAP server directly with the same
  token, which the Hub hands them.

## Limits

- **Less tested** than the other connection types.
- Only Bearer tokens; no username and password, no OAuth sign-in flow for JMAP servers.
- The add dialog offers JMAP for Fastmail only.
- If the server cannot report changes since the last sync (for example after a long time
  offline), the Hub downloads the message list again. Messages deleted at the server during that
  gap may stay in Postern.
- Calendars and contacts over JMAP are not used.

## Troubleshooting

| Symptom | Cause | Fix |
|---|---|---|
| **The sign-in was rejected.** | The token is wrong, expired or revoked. | Create a new token; for an existing mailbox use **Update sign-in**. |
| Reading works, sending fails | The token has no submission access, or your From address is not an identity at the server. | Create a token with send access; add the address as an identity at the server. |
| Mail sent from an alias shows another address | The server has no identity for that address, so the first identity was used. | Add the alias as an identity at the server. |
| Deleted messages still show | Changes during a gap were not reported. | Delete them in Postern too, or remove the mailbox and add it again. |
| Anything else odd | JMAP is less tested. | Connect the account over [IMAP](https://docs.posternmail.app/providers/imap/) instead, and report the problem. |
