Mail relay: review round 2 — the store is keyed by host, a copied database does not enrol by itself

- Q-1 one entry per host (iapl:mail-relay:site:<host>); a read never deletes or writes; another host's
  entry is neither used nor touched (a developer's process on the live database, www and apex, a copy)
- a database that holds another host's connection and none of this site's does not enrol by itself:
  "Connect again" does, once; mail.relay.otherHosts ('wait' | 'enrol' | the site's own other hosts);
  panel text and doctor finding; a site with an empty store enrols by itself as before
- Q-2 the file limit answers from what is stored and never asks the service
- Q-3 a file whose mail was not confirmed is not reported as a wrong file, and no notice mail follows
- Q-4 its own text when the access-key field is off
- D-1 docs for open enrolment; staging, copies and several hosts

Co-Authored-By: Claude Fable 5.2 <[email protected]>
This commit is contained in:
Radosław Smoliński
2026-11-25 23:14:11 +01:00
co-authored by Claude Fable 5.2
parent edee3a321f
commit 85ed92bb89
31 changed files with 467 additions and 211 deletions
+38 -19
View File
@@ -78,8 +78,10 @@ What the site needs for it:
443, **without a redirect** — the service follows none. No basic auth, no firewall rule, no maintenance page in
front of it. (Coolify: nothing to set; the route is part of Payload's API.)
- **Outbound HTTPS** from the server to `webservices.intecion.net`.
- A host Intecion has **listed** is active at once. Any other host is enrolled but **waits for approval**: mail is
not sent until Intecion approves it, then the same token works. The panel says which it is.
- **A site that passes the call-back is active at once.** Waiting for approval is the exception: the service
holds a new site back when many new sites appear at once (more than a few a day from one address or domain, or
more than its daily number in all), or when Intecion has set it to approve by hand. Mail is then not sent until
Intecion approves the site; the same token works afterwards, and the panel says so.
A site on `localhost`, on a private address or without `serverURL` is refused **by the plugin itself**, before any
call leaves the server — development machines do not contact the service. To test mail locally use SMTP (a local
@@ -126,7 +128,9 @@ The numbers are the service's, per site, and can be changed by Intecion for one
A message over a limit is refused whole (`relay-quota`, `relay-too-large`); the site is not suspended for it.
`mailAttachmentLimit(payload)` reports the file limit the service named, so a form's File field never promises
more ([forms.md](./forms.md) "Files"); until the site has enrolled it is `null` (the plugin has no number of its own).
more ([forms.md](./forms.md) "Files"). It answers from what is stored — never by asking the service while a page
is read — and is renewed after a send, once an hour; until the site has enrolled and sent once it is `null` (the
plugin has no number of its own).
**Account mail is limited by the site itself.** "Forgot password" is a visitor's lever like a form, and the
service lets account mail use the whole hour. So the relay transport holds back more than **5 account e-mails to
@@ -194,13 +198,13 @@ await runWithMailKind('account', () => sendWelcomeMails(payload, user))
### The token
- Kept in Payload's key-value store (`payload.kv`, the `payload-kv` collection Payload itself adds; key
`RELAY_KV_KEY` = `iapl:mail-relay`). **No field, no column, no migration.** That collection refuses every
one entry per host under `RELAY_KV_KEY` = `iapl:mail-relay`). **No field, no column, no migration.** That collection refuses every
operation through access control and is hidden in the panel, so the token cannot be read over REST or GraphQL —
not by an admin either. It is never logged and never sent to a browser.
- **The token belongs to the host it was issued for.** A store found on another host — a production database
copied to a staging domain, a site moved to a new domain — is not used: the copy forgets the token (nothing is
revoked, the other site keeps working), starts unenrolled and enrols as itself, with its own token, limits and
approval. The start log says so once.
- **The token belongs to the host it was issued for, and is stored under that host** (key
`iapl:mail-relay:site:<host>`). A site reads and writes its own entry only; another host's entry in the same
database — production's in a copy, the old domain's after a move, the live site's when a developer's process
reads the live database — is neither used nor touched. **A read never deletes or changes anything.**
- The token works only from the server addresses the site enrolled from. After a move to another server the
service answers "enrol again"; the site does, by the same call-back, and sends. A site whose requests leave from
many changing addresses (serverless, a pool of egress addresses) needs its limit of addresses raised by Intecion.
@@ -248,16 +252,29 @@ await runWithMailKind('account', () => sendWelcomeMails(payload, user))
- Encryption at rest: none, like `smtpPassword`. A token read from a database dump is of little use — it does not
work from another server address.
### Staging and copies
### Staging, copies and several hosts
- A staging site on its own domain is **its own site** to the service: its own enrolment, token, limits and
approval ("waiting for approval" until Intecion approves it, unless its host is listed).
- **A copy of production's database does not carry production's connection.** The stored token is tied to the host
it was issued for; on another host it is forgotten (never revoked), and the copy enrols as itself. This also holds
on the same server, where production's token would otherwise work.
- "Disconnect" on a copy revokes nothing of production's.
- A staging copy that must not send at all: `iapl({ mail: { relay: false } })` there, or SMTP to a catcher.
- Not covered: a copy that keeps production's `serverURL` is the same site to the plugin.
- **A site that passes the call-back is active at once** and can send. A staging site on its own domain is its own
site to the service: its own enrolment, token and limits.
- **A copy of production's database does not connect by itself.** Its data is production's — real customers'
addresses in form submissions and accounts — and a copy that enrolled by itself would mail real people as soon
as a form or a password reset ran. So a site whose database already holds the connection of **another host** and
none of its own stays "not connected": sends report `relay-refused` (cause `client-other-host`), the state block
says "The data comes from another site (…), so this site did not connect by itself", the doctor reports it
(`mail-relay-state`), and no call leaves the server. An admin who wants the copy to send presses **Connect
again**, once; from then on it is a site of its own and heals by itself.
- **A site before launch is not affected:** with an empty store it enrols by itself on its first e-mail.
- **A copy that must never send:** `iapl({ mail: { relay: false } })` there, or SMTP to a catcher. That is the
safe set-up for staging; "not connected" only protects until somebody presses the button.
- **`www.` and the bare domain** are one site: either enrols by itself beside the other (each keeps its own entry).
- **A moved domain** (the same data under a new host) looks like a copy: after the move press **Connect again**
once, or name the old host as the site's own — `mail: { relay: { otherHosts: ['old-domain.example'] } }` — and
the site enrols by itself. The same list is for a second domain of one site.
- **`otherHosts: 'enrol'`** switches the rule off: a site enrols by itself whatever else the database holds.
- Production's connection is never used, changed or revoked by a copy — "Disconnect" on a copy included, and on the
same server too. A developer's process on `localhost` reading the live database changes nothing either.
- Not covered: a copy that keeps production's `serverURL` is the same site to the plugin (and to the service, if it
can be called back at that host).
### The state block in the panel
@@ -290,7 +307,7 @@ the service), each with a text in the editor's language:
| Code | Meaning | What to do |
|---|---|---|
| `relay-pending` | enrolled, waiting for approval by Intecion | Intecion approves the host; nothing to do on the site |
| `relay-pending` | enrolled, but held for approval by Intecion — the exception (many new sites at once, or approval by hand); a site is normally active as soon as it enrols | Intecion approves the host; nothing to do on the site |
| `relay-suspended` | stopped by Intecion | contact Intecion; SMTP in the panel sends meanwhile |
| `relay-refused` | the site could not enrol; or a token issued by hand stopped working (new server address, token no longer valid) | "When the site cannot be confirmed" below; hand-issued: ask Intecion for the address to be added or for a new token |
| `relay-disconnected` | an admin pressed "Disconnect" | "Connect again", or fill in SMTP |
@@ -332,6 +349,7 @@ message); "Connect again" asks at once. Other causes: `host-not-allowed` (not a
| `relay: false` | — | switches the mail service off: no enrolment, no outbound call, no confirm route, no state block, the panel wording of 1.16 |
| `url` | `RELAY_BASE_URL` (`https://webservices.intecion.net/mail`) | another base address — a relay of your own that speaks the same contract |
| `host` | host of `serverURL` (`relayHost(payload, options)`) | the public host the service calls back |
| `otherHosts` | `'wait'` | a database that holds another host's connection and none of this site's (a copy, a moved domain): `'wait'` = no enrolment until "Connect again"; a list = those hosts are this site's own; `'enrol'` = enrol by itself anyway |
| `enrol` | `'auto'` | `'manual'`: only "Connect again" or `enrolRelay()` enrols. `false`: never (the token comes from `token` or `setRelayToken`) |
| `accessKeyField` | `false` | `true` shows "Enter an access key" in the state block and lets its route store a hand-issued token an admin pastes |
| `token` | — | a token from elsewhere (`string` or a function): the stored token is not used and the site does not enrol |
@@ -501,7 +519,8 @@ Works on any `text` field. After wiring it in a project you may need
To the mail service (when the owner says so):
1. Upgrade; check that `serverURL` is the site's public address.
2. Intecion lists the host on the service (or approves it after the first send).
2. Nothing to arrange with Intecion beforehand: the site is active as soon as it enrols (in the rare case that it
is held for approval, the panel says so).
3. Remove the four `GRAPH_*` variables in Coolify and redeploy. If "Sending method" says Microsoft Graph, set it
to "Automatic".
4. Site integrations → E-mail sending → send a test e-mail: the answer says "through IWSN".