Mail relay: contract 1.6.0, the token tied to its host, IWSN in the panel

- contracts/mail-relay refreshed from IWDL 83af8c6 (1.6.0)
- an answer that is not the service's JSON is 'not confirmed' unless its status is 400 to 499
- a site with a token issued by hand does not enrol to heal: it stops and says what to ask Intecion for
- a store made on another host (a database copied to staging) is not used: the copy enrols as itself, nothing is revoked
- the panel calls the service IWSN (RELAY_SHORT_NAME); docs, logs and the doctor keep the full name

Co-Authored-By: Claude Fable 5.2 <[email protected]>
This commit is contained in:
Radosław Smoliński
2026-11-25 21:51:47 +01:00
co-authored by Claude Fable 5.2
parent 7d766b6d58
commit 0ee74ab2a4
36 changed files with 380 additions and 128 deletions
+5 -3
View File
@@ -81,12 +81,14 @@ once there are more than 20.
keep their doctor rule ids, so settings in a project's doctor file still match.
### Added
- **The Intecion Notifications Webservice as the default e-mail transport** ([email.md](./email.md), AGENT.md §7.2).
- **The Intecion Notifications Webservice (IWSN) as the default e-mail transport** ([email.md](./email.md), AGENT.md §7.2).
The admin panel calls it **IWSN**; docs, logs and the doctor use the full name.
`mailAdapter()` now picks per send: Graph when the panel says so and `GRAPH_*` is set → SMTP when the panel has a
server → Graph when `GRAPH_*` is set → the mail service → not configured (`resolveMailTransport`). The site holds no
mail key: it enrols by a call-back to its own domain and keeps its token in `payload-kv` (key `iapl:mail-relay` —
no field, no column; not readable over REST or GraphQL, an admin included; proven by a test). The token is bound to
the site's server addresses, rotated every 90 days, healed by re-enrolment. One message = one `Idempotency-Key` and
the site's server addresses and to the host it was issued for (a database copied to another host enrols as itself),
rotated every 90 days, healed by re-enrolment. One message = one `Idempotency-Key` and
one encoding across at most three attempts; a send with no answer is reported as **not confirmed** (it may be out)
and cannot double when sent again. Every message says what it is (form notification, form confirmation, account,
test, system): form mail and Payload's "forgot password" are marked by the plugin; `withMailKind` /
@@ -109,7 +111,7 @@ once there are more than 20.
`withMailKind`, `runWithMailKind`, `mailKindOf`, `expectMailTo`, `buildFormMailKindHook`, `createFakeRelay` (the
service in memory, for tests), the constants `RELAY_*`, `MAIL_KINDS`, `MAIL_KIND`, `GRAPH_DEPRECATION_NOTICE`, and
their types; `MailRelayStatus` from `/admin`.
- The wire contract of the service (version 1.5.0) is copied in the repository (`contracts/mail-relay/`) with a
- The wire contract of the service (version 1.6.0) is copied in the repository (`contracts/mail-relay/`) with a
checksum test; every example of it runs against the plugin's fake service and against the plugin's client.
- **`iapl-doctor` rule `legacy-names`** (info): lists the old names a project still uses, each with the new one.
Information, not a defect. A warning only for `iapl-doctor.json` and `ipal-doctor.json` side by side, or one variable
+5 -3
View File
@@ -121,7 +121,7 @@ the ready-to-send list is in **iapl-setup** stage 0 (iapl-site phase 0 uses the
| Languages | which locales, the default locale, URL structure (`/pl/…` for every language, or the default without a prefix) |
| Styling | a design system / `DESIGN.md` or plain Tailwind tokens, brand colours, fonts, light/dark theme |
| Content | the pages, the collections (blog, case studies, products…), archive pages |
| Forms | which forms, who receives them; e-mail: the built-in mail service by default — ask only whether the client wants its **own SMTP server and sender address** (never offer Microsoft Graph: deprecated) |
| Forms | which forms, who receives them; e-mail: the Intecion mail service (IWSN in the panel) by default — ask only whether the client wants its **own SMTP server and sender address** (never offer Microsoft Graph: deprecated) |
| Analytics and consent | GA4 / GTM / pixels, Consent Mode basic or advanced, cookie banner mode, cookie scan |
| SEO / GEO | market and local business data, AI crawler policy (llms.txt, Markdown, MCP, AI bots) |
| Data and media | database (Postgres or MongoDB) and its names (`<domain without dots>_prod` / `_dev` — derive, then confirm), media storage (R2 or local disk) |
@@ -1249,6 +1249,9 @@ add missing hosts with flags / `extra`; (3) change `mode` to `'enforce'` in both
### 7.2 E-mail — the mail service (default), SMTP (on request), Graph (deprecated)
The service is the **Intecion Notifications Webservice**; the admin panel calls it **IWSN** (constant
`RELAY_SHORT_NAME`) — say "IWSN" when you tell a client what the panel shows.
**What you wire — three lines, every site:**
```ts
@@ -1281,8 +1284,7 @@ the mail service → nothing (`mail: { relay: false }` and no SMTP). A site with
the mail service that is where replies go; the service's own address has no mailbox.
5. Intecion has listed the host; otherwise the site enrols and waits for approval (`relay-pending`).
**Verify:** Site integrations → E-mail sending → the block "How e-mails are sent" says "Connected to the built-in
mail service"; **Send test e-mail** answers "through the built-in mail service, as <name>"; the mail arrives from
**Verify:** Site integrations → E-mail sending → the block "How e-mails are sent" says "Connected to IWSN"; **Send test e-mail** answers "through IWSN, as <name>"; the mail arrives from
`[email protected]` with the client's name and `Reply-To` the client's address; `iapl-doctor
--deep --url <site>` reports no `mail-*` finding. On `localhost` the plugin refuses to enrol (nothing leaves the machine): test
mail locally with SMTP (Mailpit) or `createFakeRelay()`.
+2
View File
@@ -101,6 +101,8 @@ 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") |
| 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 |
| `relay-disconnected` | an admin pressed "Disconnect" | "Connect again", or SMTP |
+1 -1
View File
@@ -22,7 +22,7 @@ Full reference: `node_modules/@intecion/ipal-kit/docs/doctor.md`.
2. Show the user the **full output**. Every finding names its rule, the file, a fix and a doc.
3. Fix every `error`. A `warning` is drift — fix it or tell the user why not. `info` is a note.
E-mail findings (`--deep`): `mail-transport` (nothing set up, or sending fails), `mail-relay-state` (the site's state
with the Intecion mail service: waiting for approval, stopped, refused, disconnected, a replaced sender name),
with the Intecion mail service (IWSN in the panel): waiting for approval, stopped, refused, disconnected, a replaced sender name),
`mail-reply-address`, `mail-graph-deprecated`, `mail-relay-route` (trailing slashes, another API route, a redirect or a
block in front of `/api/iapl/mail-relay/confirm`) — fixes: `iapl-debug` "Consent / analytics / forms / email".
4. A deliberate exception (the owner's decision) goes into `iapl-doctor.json` **with a reason** — the same reason as in
+1 -1
View File
@@ -109,7 +109,7 @@ Never build this by hand (your own `<input type="file">`, upload route or upload
the visitor that the problem is the **file**, why, and what to do (a smaller file, another format; on an
optional field also "send the form without the file"). They show at the File field; what the visitor typed stays.
6. Mail size: **Site integrations → E-mail sending → Test e-mail** with **Attach a 10 MB test file** must arrive.
The mail service (the default transport): 10 MB for all files of one message unless Intecion set another number
The mail service (the default transport) (IWSN in the panel): 10 MB for all files of one message unless Intecion set another number
for the site — the form's limit follows what the service reports by itself, and programs and scripts are refused.
SMTP: the provider's limit decides (a 10 MB server limit carries only ~7 MB of file — lower the field's
maximum). Microsoft Graph: files of 3 MB and more need the `Mail.ReadWrite` permission on the agency app
+2 -4
View File
@@ -43,7 +43,7 @@ Before I set up the site I need your decisions on:
1. Languages: which ones, which is the default, URLs — every language with a prefix (/pl/…, /en/…) or the default without one?
2. Styling: a design system / DESIGN.md, or Tailwind tokens from scratch? Brand colours, fonts, light/dark theme?
3. Pages and content: which pages? Lists with their own URLs (blog, case studies, products) and their archive pages?
4. Forms: which forms, who receives the submissions? E-mail works through the built-in Intecion mail service with no
4. Forms: which forms, who receives the submissions? E-mail works through the built-in Intecion mail service (IWSN in the panel) with no
setup — does the client want its **own SMTP server and sender address** instead? (Never offer Microsoft Graph: deprecated.)
5. Analytics and consent: GA4 / GTM / Meta / other pixels? Consent Mode basic or advanced? Cookie dialog
inline / modal / detailed? Cookie scan of the finished site?
@@ -646,9 +646,7 @@ scaling (5). `●` routes for pages need the database at build time (PROGRAMISTA
6. **Notifications**: form messages in every language.
7. **Site integrations → E-mail sending**: "Sender name" (the client's name; empty = the site name) and **"Sender
address"** (the client's address: with the mail service replies go there). SMTP fields **only** when the client asked
for its own server. On the production domain: the block "How e-mails are sent" must say "Connected to the built-in mail
service" ("waiting for approval" = ask Intecion to approve the host), then **Send test e-mail** → "through the built-in
mail service". Turnstile (for testing site
for its own server. On the production domain: the block "How e-mails are sent" must say "Connected to IWSN" ("waiting for approval" = ask Intecion to approve the host), then **Send test e-mail** → "through IWSN". Turnstile (for testing site
`1x00000000000000000000AA`, secret `1x0000000000000000000000000000000AA`; production keys from the client), analytics/pixel
IDs, IndexNow → generate key. Mail/Turnstile errors show up as a dashboard alert.
8. **Forms**: check the addresses in the Emails tab of the seeded forms.
+1 -1
View File
@@ -552,7 +552,7 @@ ipal-kit"). **Do not rename anything in the project unless the owner asks.**
**Check:** `pnpm exec iapl-doctor` shows no new error or warning (new rules: `legacy-names`, `storage-names`); the site
builds; the panel opens; the old commands (`pnpm exec ipal-doctor`) still run.
**→ 1.17.0, e-mail (the Intecion mail service is the default transport; Microsoft Graph deprecated; CHANGELOG 1.17.0;
**→ 1.17.0, e-mail (the Intecion mail service (IWSN in the panel) is the default transport; Microsoft Graph deprecated; CHANGELOG 1.17.0;
PROGRAMISTA §6, item 73; email.md; AGENT.md §7.2) — nothing to run; read which case the site is:**
1. **Every site:** no schema change, no migration, no import-map change. The e-mail tab gains the block "How e-mails
are sent" and new wording ("Automatic", "Own SMTP server").
+3 -2
View File
@@ -54,8 +54,9 @@ Mail needs **no variable**. A site with no SMTP server in the panel sends throug
- **That route reachable from the internet** — no basic auth on the Coolify app, no firewall or WAF rule in front of
`/api/iapl/`; behind Cloudflare leave it uncached and unchallenged.
- **Outbound HTTPS** to `webservices.intecion.net`.
- A staging copy on its own domain enrols as its own site (its own token, its own limits, its own approval); a
staging copy that must not send: `iapl({ mail: { relay: false } })` or SMTP to a catcher.
- A staging copy on its own domain enrols as its own site (its own token, its own limits, its own approval) —
**also when its database is a copy of production's**: the stored token is tied to production's host and is not
used on another one. A staging copy that must not send: `iapl({ mail: { relay: false } })` or SMTP to a catcher.
- Several containers of one site share the database, so they share the token; a restore of an old database dump
brings back an old token — the site then enrols again by itself on its next e-mail.
+22 -8
View File
@@ -1,7 +1,8 @@
# email
Mail works with **no setup**: a site with no SMTP server in the panel sends through the
**Intecion Notifications Webservice** (below: "the mail service"), from
**Intecion Notifications Webservice** — **IWSN** for short, the name the admin panel uses (constant
`RELAY_SHORT_NAME`); below also "the mail service" — from
`[email protected]`, under the site's own sender name. Two more transports exist:
| Transport | When | Sender address |
@@ -165,11 +166,17 @@ await runWithMailKind('account', () => sendWelcomeMails(payload, user))
- A message is encoded **once**; exactly those bytes go out on every attempt, under one `Idempotency-Key`. At most
**three attempts**, 30 seconds each, at most ten seconds of waiting between them in all — and only after an answer
the service marks retryable, or after no answer. An enrolment on the way is not one of the three.
- **No answer at all** (time-out, connection lost) is reported as `relay-not-confirmed` with `confirmed: false`: the
message **may have been sent**. Sending the same message again within 24 hours reuses the same key, so the
service answers with what happened to the first attempt (`replayed: true`) and no second mail goes out.
- **No answer of the service** — a time-out, a lost connection, or an answer that is not the service's own JSON (an
error page of the network in front, a cut-off body) with any status outside 400–499, `200` included — is reported
as `relay-not-confirmed` with `confirmed: false`: the message **may have been sent**. Such an answer with a status
from 400 to 499 was turned away before the service handled it: `relay-unreachable`, not sent.
- **"Not confirmed" is final for that message.** The plugin keeps no unsent mail (no stored outbox), so it does not
try again by itself after the report. While the same process is running, the same message sent again within
24 hours goes out under the same key — the service then answers with what happened to the first attempt
(`replayed: true`) and no second mail goes out. After a restart, or from another instance of the site, a repeat
(a visitor submitting the form again) is a new message: if the first one did go out, the recipient gets two.
That is why the panel says "it may have been sent; check the mailbox before trying again".
- The form **keeps working** meanwhile — the submission is saved in Form Submissions; only the mail is missing.
- There is no stored outbox: a message that failed is not sent later by itself.
### The token
@@ -177,6 +184,10 @@ await runWithMailKind('account', () => sendWelcomeMails(payload, user))
`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 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.
@@ -188,6 +199,9 @@ await runWithMailKind('account', () => sendWelcomeMails(payload, user))
the site from enrolling by itself until "Connect again" (`enrolRelay(payload, { force: true })`).
- **A token issued by hand** — for a site the service cannot call back (behind a firewall): Intecion issues one,
an admin enters it in the state block ("Enter an access key"), or a script calls `setRelayToken(payload, token)`.
**Such a site cannot heal by itself:** it never enrols on its own. When the service no longer knows its server
address (after a move, or a second server) or its token, the send reports `relay-refused` and the state block
says what to ask Intecion for — the new address added, or a new token.
- 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.
@@ -223,7 +237,7 @@ the service), each with a text in the editor's language:
|---|---|---|
| `relay-pending` | enrolled, waiting for approval by Intecion | 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 | "When the site cannot be confirmed" below |
| `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 |
| `relay-quota` | a limit of the site or of the whole service; too many recipients; the site's own limit on account mail | wait; ask Intecion for other limits; SMTP for a site that sends more |
| `relay-too-large` | text or files over the service's limit | a smaller file; `forms.attachments.maxFileSize`; SMTP |
@@ -430,7 +444,7 @@ To the mail service (when the owner says so):
2. Intecion lists the host on the service (or approves it after the first send).
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 the built-in mail service".
4. Site integrations → E-mail sending → send a test e-mail: the answer says "through IWSN".
5. Check "Sender name" and "Sender address" (now the reply address), and tell the client that mail now comes from
`[email protected]` instead of the present mailbox (allow-lists, filters).
@@ -576,7 +590,7 @@ The large path, step by step, and what happens when it fails:
## Test send — button in the panel
The E-mail sending tab has a **Send test e-mail** button: enter an address, click, and a test mail goes out through
the CURRENT transport (`payload.sendEmail`). The answer names the transport ("through the built-in mail service,
the CURRENT transport (`payload.sendEmail`). The answer names the transport ("through IWSN,
as …", "through your SMTP server") and, for the mail service, the sender name that was used. Tick **Attach a 10 MB
test file** to check that a file of that size gets through ("Attachments" above). Endpoint
`POST /api/ipal/test-email`, body `{ to, attachmentMB? }` (`admin` role only — needs roles from the `access` option:
+2 -1
View File
@@ -998,13 +998,14 @@ document, the fields under `version`, where field hooks do not run: the global's
## The mail service's token and its public route (`mail.relay`)
A site that sends through the Intecion Notifications Webservice ([email.md](./email.md)) holds one secret: its own
A site that sends through the Intecion Notifications Webservice (IWSN in the panel; [email.md](./email.md)) holds one secret: its own
token. What protects it, and what the new public route can and cannot do:
| | |
|---|---|
| **No key in the package** | The plugin carries the service's address and nothing else. A site gets its token by proving it is served at its host: it makes a nonce, the service calls `POST https://<host>/api/iapl/mail-relay/confirm` with the nonce and a token, and only an answer that hashes both makes the token valid |
| **Where the token is** | `payload-kv`, key `iapl:mail-relay`. The collection refuses every operation through access control (`read`, `create`, `update`, `delete` are `false`) and is hidden: REST, GraphQL and the panel cannot reach it — an admin included (test: `test/mailRelayHttp.test.ts`). Server code with the Local API can, like `smtpPassword`. It is stored as it is (no encryption at rest), never logged, never sent to a browser, never part of a route's answer |
| **A database copied to another host** | the token is tied to the host it was issued for: a copy on a staging domain does not use production's token — it forgets it, without revoking it, and enrols as itself |
| **A token read from a database dump** | does not work from another server: the service accepts a token only from the addresses the site enrolled from (IPv6: the same `/64`) and answers anything else "enrol again" — which needs the call-back to the real site. It cannot send as another site, and the limits below apply |
| **What a token can do at most** | send within the site's limits (30 an hour, 200 a day, 10 recipients, 10 MB by default) from the service's fixed address, under a sender name the service checks, with `X-Intecion-Site: <host>` on every mail. It cannot set `From`, `Return-Path` or any header, and cannot address a security alert |
| **The confirm route** | public by design, `404` with an empty body unless the body carries a nonce **this site** made in the last 5 minutes (kept as a hash, compared in constant time, single use). It stores the delivered token **beside** the one in use and never replaces a working token: a token becomes the one in use only after the service has accepted it. Rate-limited per address (10 a minute, `mail.relay.confirmRateLimit`). A stranger who calls it learns nothing and changes nothing |