Mail relay: the access-key field is off by default (mail.relay.accessKeyField)

A token issued by hand is set by a developer: setRelayToken() from a script, or mail.relay.token.
The panel field and its route take a token only when the project switches the field on. Docs and
AGENT.md say when such a token is needed and how to set it; a token of another host is refused on
every way in.

Co-Authored-By: Claude Fable 5.2 <[email protected]>
This commit is contained in:
Radosław Smoliński
2026-11-25 22:25:34 +01:00
co-authored by Claude Fable 5.2
parent 1a11cefffa
commit edee3a321f
11 changed files with 87 additions and 21 deletions
+9
View File
@@ -1316,6 +1316,7 @@ overrides per adapter; `resolveRelayOptions` reads what is in effect):
| `url` | `RELAY_BASE_URL` | a relay of your own (same contract) |
| `host` | host of `serverURL` (`relayHost`, `isPublicHost`) | the public host the service calls back |
| `enrol` | `'auto'` | `'manual'` (only "Connect again" / `enrolRelay`), `false` (token from `token` / `setRelayToken`) |
| `accessKeyField` | `false` | `true`: admins get "Enter an access key" in the state block (a hand-issued token) |
| `token` | — | a token from elsewhere; nothing is stored, the site does not enrol |
| `senderName` | panel → site name (`relaySenderName`) | fixed name or function |
| `kind` | — | kind of a message nobody marked |
@@ -1354,6 +1355,14 @@ needs more: Intecion raises the limits, or SMTP.
| Constants | `RELAY_BASE_URL`, `RELAY_CONFIRM_PATH`, `RELAY_CONTRACT_VERSION`, `RELAY_DEFAULTS`, `RELAY_KV_KEY`, `RELAY_PRODUCT`, `RELAY_SENDER_ADDRESS`, `RELAY_SERVICE_NAME` |
| Tests without the service | `createFakeRelay` (`FakeRelay`, `FakeRelayOptions`, `FakeRelayMail`, `FakeRelayLimits`): `mailAdapter({ relay: { url: fake.url, fetchImpl: fake.fetch } })`, then assert on `fake.outbox` |
**A token issued by hand** is needed only for a site the service cannot call back (behind a firewall or basic
auth, on a private network). Intecion issues it for the site's host; you set it, never the client: once from a
script — `await setRelayToken(payload, token)` under `pnpm payload run` (stored in `payload.kv`, rotated by the
plugin) — or as the deployment's secret, `mail: { relay: { enrol: false, token: () => process.env.MY_MAIL_TOKEN } }`.
The panel has no field for it unless the project sets `mail: { relay: { accessKeyField: true } }`. Such a site
cannot heal by itself: after a move to another server it reports `relay-refused` until Intecion adds the address
or issues a new token. A token of another host is refused on every way in.
**Never:** read or print the token (`payload.kv`, key `iapl:mail-relay`); add a field or env variable for it; call
the service from a client component; retry a failed send in a loop of your own; mark form mail as `account`.
+1 -1
View File
@@ -101,7 +101,7 @@ through this procedure. Ask only when you are missing something you cannot get y
| state block: "Not connected yet" on the production domain | no e-mail was sent yet | **Send test e-mail** (the site enrols on its first send) or "Connect again" |
| `relay-refused` / "The mail service could not reach this site at …" (cause `callback-failed`) | `unreachable` / `timeout`: firewall, private network, wrong public host in `serverURL`; `redirect`: `trailingSlash: true`, apex → `www`, a language redirect; `status`: route blocked, missing (`mail: { relay: false }`?) or another `routes.api`; `confirmation`: a proxy rewrites the answer | `curl -i -X POST https://<host>/api/iapl/mail-relay/confirm -d '{}' -H 'content-type: application/json'` must answer **404 with an empty body, no redirect**; fix `serverURL` / `mail.relay.host`, or ask Intecion to set the site's confirm address (path ending in `/confirm/` with trailing slashes); then "Connect again" (the site does not retry by itself for 15 min). email.md "When the site cannot be confirmed" |
| `relay-refused`, cause `host-not-allowed` / "This site has no public address yet" | the site runs on `localhost`, a private name, or `serverURL` is empty | expected in development (use SMTP / Mailpit there); in production set `serverURL` |
| `relay-refused` on a site whose token was entered by hand ("does not know the server this site now runs on" / "access key … no longer valid") | the site moved or got a second server, or its token expired; a site with a hand-issued token cannot enrol by itself | Intecion adds the server's address, or issues a new token (state block → "Enter an access key") |
| `relay-refused` on a site whose token was entered by hand ("does not know the server this site now runs on" / "access key … no longer valid") | the site moved or got a second server, or its token expired; a site with a hand-issued token cannot enrol by itself | Intecion adds the server's address, or issues a new token — set it with `setRelayToken(payload, token)` from a script (`pnpm payload run`), or in the panel when the project has `mail.relay.accessKeyField: true` (email.md "The token") |
| staging sends nothing after its database was copied from production: "Not connected yet" / "waiting for approval" | expected: production's token is tied to production's host and is not used on the copy; the copy enrolled as itself | Intecion approves the staging host, or staging uses SMTP / `mail: { relay: false }` |
| `relay-pending` / "waiting for approval" | the host is not on Intecion's list | Intecion approves it on the service; nothing to change on the site; the same token then works |
| `relay-suspended` | Intecion stopped the site (abuse, a flood from a form) | contact Intecion; fill in SMTP meanwhile |