From a2b07b1dc1846f5746fdaf5651e32cc965b0cfd7 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Rados=C5=82aw=20Smoli=C5=84ski?= Date: Wed, 25 Nov 2026 22:07:10 +0100 Subject: [PATCH] =?UTF-8?q?Mail=20relay:=20review=20of=207d766b6=20?= =?UTF-8?q?=E2=80=94=20R-1=20to=20R-12,=20four=20mutations,=20two=20senten?= =?UTF-8?q?ces?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit - R-1 a delivered token becomes the one in use only on 200 or a refusal given after authentication - R-2 a token of another site is refused by what /v1/status says (access-key field, scripts); docs for staging - R-3 the confirm route looks the nonce up first and counts only refused calls - R-4 one budget of time per message (10 s, 30 s with files), enrolment and retries included - R-5 'Disconnect' without the service's answer is not confirmed and keeps the token to try again - R-6 no enrolment without the confirm route in the config - R-7 half an SMTP set-up: one log line and a hint in the panel - R-8 to R-10, R-12 docs; R-11 the last failure stays in the state block - tests for redirect: manual, the candidate's nonce, the expectation taken back, one recipient only Co-Authored-By: Claude Fable 5.2 --- docs/CHANGELOG.md | 11 +- docs/agent/AGENT.md | 5 +- docs/agent/skills/iapl-debug/SKILL.md | 6 +- docs/agent/skills/iapl-upgrade/SKILL.md | 5 +- docs/email.md | 45 ++- docs/security.md | 9 +- reference/.agents/skills/iapl-debug/SKILL.md | 6 +- .../.agents/skills/iapl-upgrade/SKILL.md | 5 +- .../components/MailRelayStatus.tsx | 13 +- src/modules/admin-i18n/texts/integrations.ts | 10 + src/modules/email/mailAdapter.ts | 12 +- src/modules/email/relay/client.ts | 3 +- src/modules/email/relay/confirm.ts | 20 +- src/modules/email/relay/constants.ts | 7 + src/modules/email/relay/index.ts | 6 +- src/modules/email/relay/options.ts | 9 +- src/modules/email/relay/panel.ts | 36 ++- src/modules/email/relay/send.ts | 51 +++- src/modules/email/relay/session.ts | 100 +++++-- src/modules/email/relay/store.ts | 11 +- test/mailRelay.test.ts | 259 +++++++++++++++++- test/mailRelay/helpers.ts | 4 +- test/mailRelayHttp.test.ts | 20 ++ 23 files changed, 584 insertions(+), 69 deletions(-) diff --git a/docs/CHANGELOG.md b/docs/CHANGELOG.md index 28ab8d0..175c5bb 100644 --- a/docs/CHANGELOG.md +++ b/docs/CHANGELOG.md @@ -27,7 +27,9 @@ once there are more than 20. > `relay-unreachable` and sends nothing, as it sent nothing before.** ### Requires project changes -- **Nothing has to be run.** The e-mail tab of Site integrations has a new block ("How e-mails are sent"); it is +- **A CI that compares generated types:** `payload generate:types` gives a diff on upgrade — four field descriptions + of Site integrations changed (no type did). Run it and commit `payload-types.ts`. The import map does not change. +- **Nothing else has to be run.** The e-mail tab of Site integrations has a new block ("How e-mails are sent"); it is rendered by the status banner already in every import map, so `generate:importmap` gives no diff. No field was added; "Sending method" keeps its two stored values. - **What changes for an existing site on upgrade — e-mail:** @@ -39,6 +41,7 @@ once there are more than 20. | `GRAPH_*` set, "Sending method" on SMTP, no SMTP server (mail failed until now) | Mail goes through Graph | fill in SMTP, or remove the variables | | Neither (mail failed until now with "not configured") | **An outbound call:** on the next e-mail the site enrols with the service — `POST https://webservices.intecion.net/mail/v1/enrol` with its host and the plugin version — and then sends through it, from `notification@webservices.intecion.net`. A host Intecion has not listed waits for approval first | `iapl({ mail: { relay: false } })` | | Any site with the mail service enabled (the default) | **A new public route:** `POST /api/iapl/mail-relay/confirm` — answers `404` and changes nothing unless the site itself started an enrolment in the last 5 minutes; rate-limited. Three admin-only routes beside it (`…/status`, `…/connect`, `…/disconnect`) | `mail: { relay: false }` removes all four | + | SMTP **half** filled in — a server or a user name, but not server, user name and password (until now: refused, "Fill in the server, user name and password") | Sent through the mail service; one line in the server log and a hint in the state block say that the SMTP settings are incomplete | complete or empty the SMTP fields; `mail: { relay: false }` | | "Microsoft Graph" chosen in the panel but `GRAPH_*` missing (until now: SMTP with a warning) | SMTP if filled in, otherwise the mail service | as above | | A site on `localhost` or without `serverURL` | Refused by the plugin itself; nothing leaves the machine. Development: SMTP (a local catcher) as before | — | @@ -90,13 +93,15 @@ once there are more than 20. 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, + and, while the same process runs, goes out under the same key when sent again (after a restart or from another + instance a repeat is a new message). One message has one budget of time — 10 seconds, 30 with files + (`mail.relay.totalTimeoutMs`) — so a service that hangs does not hold a form's visitor for the sum of the attempts. 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` / `runWithMailKind` for a project's own. Account mail is limited by the site itself (5 an hour to one address, 10 by one visitor; `mail.relay.accountMail`). Limits and the file size come from the service (30 an hour, 200 a day, 10 MB unless Intecion set others); `mailAttachmentLimit` reports the latter. - **Plugin option `mail`**: `mail: { relay: false | { url, host, enrol, token, senderName, kind, accountMail, - confirmRateLimit, timeoutMs, retryBackoffMs, fetchImpl }, graphDeprecationWarning }`; `mailAdapter({ relay })`. + confirmRateLimit, totalTimeoutMs, timeoutMs, retryBackoffMs, fetchImpl }, graphDeprecationWarning }`; `mailAdapter({ relay })`. - **Panel:** the state block on the e-mail tab (transport in effect, the site's state with the service, sender and reply address, what is left of the limits, a replaced sender name; "Check now", "Connect again", "Disconnect", "Enter an access key"); "Sending method" reads "Automatic" / "Microsoft Graph (deprecated)"; the server field reads diff --git a/docs/agent/AGENT.md b/docs/agent/AGENT.md index 93a1472..fc70bb5 100644 --- a/docs/agent/AGENT.md +++ b/docs/agent/AGENT.md @@ -1321,6 +1321,7 @@ overrides per adapter; `resolveRelayOptions` reads what is in effect): | `kind` | — | kind of a message nobody marked | | `accountMail` | `{ perAddress: 5, perVisitor: 10, windowMinutes: 60 }` | the site's own limit on account mail; `false` = none | | `confirmRateLimit` | `{ max: 10, windowMs: 60000 }` | the public confirm route, per address | +| `totalTimeoutMs` | 10 s, 30 s with files | all one message may take (a visitor waits for the form) — a number or `{ plain, files }` | | `timeoutMs`, `retryBackoffMs`, `fetchImpl` | 30 s, 1 s, `fetch` | one attempt; wait between attempts; tests | | `graphDeprecationWarning` | `true` | `false` = no start warning on a Graph site (`GRAPH_DEPRECATION_NOTICE`) | @@ -1333,7 +1334,9 @@ the site itself just started an enrolment, rate-limited; allow it in any WAF or `relay-attachment-refused`, `relay-recipient-suppressed`, `relay-unreachable`, `relay-not-confirmed`, `relay-error` (and the warning `relay-name-replaced`) — what each means and what to do: `iapl-debug`, "E-mail". A send returns `RelaySendResult`; `confirmed: false` means the message **may** have been sent — do not send it again under -another content; the same message sent again reuses its key and cannot double. +another content. Inside one running process the same message sent again reuses its key and cannot double; after a +restart, or from another instance, a repeat is a new message and can. One message has one budget of time +(`totalTimeoutMs`: 10 s, 30 s with files) for enrolment, attempts and waits together. **Limits** (the service's; per site): 30 messages an hour, 200 a day, 10 recipients a message, 10 MB of files — read from the service (`mailAttachmentLimit`, `relayAttachmentLimit`), never typed into a project. A site that diff --git a/docs/agent/skills/iapl-debug/SKILL.md b/docs/agent/skills/iapl-debug/SKILL.md index 2a29c20..1f9199b 100644 --- a/docs/agent/skills/iapl-debug/SKILL.md +++ b/docs/agent/skills/iapl-debug/SKILL.md @@ -110,7 +110,11 @@ through this procedure. Ask only when you are missing something you cannot get y | `relay-too-large` / `relay-attachment-refused` | files over the service's limit (10 MB a message); a program or script as attachment | lower the File field's maximum (`iapl-form`); other file types; SMTP for larger files | | `relay-recipient-suppressed` | one recipient's mailbox bounced or complained before (for any site); nothing was sent to anybody | correct the address in the form's Emails tab; ask Intecion to clear the address | | `relay-unreachable` | the service or its mail back end failed, or the server cannot reach `webservices.intecion.net` | `curl -s https://webservices.intecion.net/mail/health` from the server → `{"ok":true}`; if it persists: SMTP, and tell Intecion | -| `relay-not-confirmed` / "may have been sent" | no answer from the service (time-out, connection lost) | check the recipient's mailbox **before** sending again; the same message sent again cannot double | +| `relay-not-confirmed` / "may have been sent" | no answer of the service: a time-out, a lost connection, an error page of a proxy in front, or the message's time budget (10 s, 30 s with files) ran out while an attempt was open | check the recipient's mailbox **before** sending again — a repeat after a restart or from another instance is a new message and can double. A service that hangs for everybody: SMTP meanwhile, tell Intecion | +| state block: "the disconnection is not confirmed" | "Disconnect" could not reach the service: the site stopped sending, the token still works there | press "Disconnect" again when the service answers | +| "This access key belongs to another site" | a token issued for another host was pasted | ask Intecion for a token for this host | +| `relay-refused`, cause `client-no-route` | the config has no `POST /api/iapl/mail-relay/confirm`: `mailAdapter()` without `iapl()`, or beside `mail: { relay: false }` | use the plugin option, or add `relayConfirmEndpoint()` to `endpoints` | +| log: "The SMTP settings in Site integrations are incomplete" | server, user name or password is missing, so the mail service carries the mail | complete the three fields, or empty them | | `relay-error` | the service refused the request as wrong (a bug), or the message has no valid recipient or no body | server log line `[iapl] mail service: …` → `iapl-plugin-gap` | | the mail arrives under the site's host instead of the client's name | the service did not accept "Sender name" (an address, a bank or provider name, mixed scripts, over 64 characters) — the state block says which name was used | another name; an honest name that is still replaced → Intecion | | replies to the site's mail are lost | "Sender address" is empty: the service's own address has no mailbox | fill it in (doctor: `mail-reply-address`) | diff --git a/docs/agent/skills/iapl-upgrade/SKILL.md b/docs/agent/skills/iapl-upgrade/SKILL.md index f0e7bbc..419c46b 100644 --- a/docs/agent/skills/iapl-upgrade/SKILL.md +++ b/docs/agent/skills/iapl-upgrade/SKILL.md @@ -554,13 +554,16 @@ builds; the panel opens; the old commands (`pnpm exec ipal-doctor`) still run. **→ 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 +1. **Every site:** no schema change, no migration, no import-map change. `pnpm payload generate:types` gives a small diff + (four field descriptions of Site integrations): run it and commit, or a CI that compares types fails. The e-mail tab gains the block "How e-mails are sent" and new wording ("Automatic", "Own SMTP server"). 2. **Which case** — Site integrations → E-mail sending, and the Coolify env: - **SMTP filled in** (server, user name, password): nothing changes, the site contacts nobody. Done. - **`GRAPH_*` set:** mail as before; one deprecation warning per start, doctor warning `mail-graph-deprecated`. Do **not** remove the variables in passing — moving the site is the owner's decision (email.md "Moving off Microsoft Graph"). Note: with `GRAPH_*` set and SMTP filled in, the panel's choice decides as before. + - **SMTP half filled in** (a server or user name without the rest; refused until now): mail now goes through the + mail service, with one log line and a hint in the panel — complete or empty the fields. - **Neither** (mail failed with "not configured" until now): **on its next e-mail the site contacts `webservices.intecion.net` with its host and the plugin version**, receives its own token through the new public route `POST /api/iapl/mail-relay/confirm`, and from then on sends from `notification@webservices.intecion.net` diff --git a/docs/email.md b/docs/email.md index 5bac58d..d42c52b 100644 --- a/docs/email.md +++ b/docs/email.md @@ -42,6 +42,10 @@ Decided on every send from Site integrations → E-mail sending, with no stored 4. Otherwise → **the mail service**, unless it is switched off (`mail: { relay: false }`). 5. Otherwise nothing is configured: the send reports `{ sent: false, code: 'not-configured' }`, as before 1.17.0. +**Half an SMTP set-up** (a server and a user name without a password, say) is not an SMTP server: until 1.16 such +a site refused to send; now its mail goes through the mail service. The server log says so once and the state +block shows "The SMTP settings below are incomplete". + - **A site with SMTP filled in never contacts the mail service.** Nothing changes for it. - **SMTP on the client's request:** an admin fills in "Own SMTP server", user name and password; from the next send the site uses the client's server and the client's own sender address. Emptying the server returns the site to @@ -157,7 +161,9 @@ await runWithMailKind('account', () => sendWelcomeMails(payload, user)) - `mailKindOf(message)` reads the mark (the key is the symbol `MAIL_KIND`; other transports ignore it). - `mail.relay.kind: (message) => MailKind | undefined` decides for messages nobody marked. - `expectMailTo(address, kind, { visitor })` says what the **next** message to one address is, for mail a library - composes by itself; the plugin uses it for Payload's account mail. It lasts ten seconds and one message. + composes by itself; the plugin uses it for Payload's account mail. It lasts ten seconds and one message. So an + **unmarked** mail of your own to the same single address within ten seconds of a "forgot password" that Payload + did not answer with a mail is counted as account mail; a marked mail (every form mail) never is. - Mark `account` only for mail to an account holder, and `form-confirmation` for mail to an address a visitor typed. A wrong kind gives a visitor room the service did not mean to give. @@ -176,7 +182,12 @@ await runWithMailKind('account', () => sendWelcomeMails(payload, user)) (`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". +- **One budget of time per message:** 10 seconds, 30 with files (`totalTimeoutMs`), for the enrolment, the + attempts and the waits together — a visitor waits for the form's answer while the mail is sent, and a service + that hangs must not hold them for the sum of the time-outs. So in practice a hanging service means one attempt. - The form **keeps working** meanwhile — the submission is saved in Form Submissions; only the mail is missing. +- The panel's banner shows the **last** send. A mail that was not sent stays visible in the state block + ("An e-mail was not sent on …", with its code) after later mail went out. ### The token @@ -196,7 +207,13 @@ await runWithMailKind('account', () => sendWelcomeMails(payload, user)) each other off (they share the database). `rotateRelayToken(payload)` does it now. - **A lost token heals itself:** the next send enrols again. - **Disconnect:** "Disconnect" in the panel (`disconnectRelay(payload)`) gives the token up on the service and stops - the site from enrolling by itself until "Connect again" (`enrolRelay(payload, { force: true })`). + the site from enrolling by itself until "Connect again" (`enrolRelay(payload, { force: true })`). It answers + `{ revoked }`: when the service could not be reached the site stops using the token at once, but the token + **still works at the service** — the panel says "not confirmed" and keeps it so that "Disconnect" can be pressed + again; only then is it revoked and forgotten. +- **A token of another site is refused.** The access-key field asks the service whose token it is before it stores + anything, and a token stored by a script is checked the same way before its first use (`/v1/status` names the + host): another site's token is not saved, not used and not revoked. - **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 @@ -205,6 +222,17 @@ 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 + +- 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. + ### The state block in the panel Site integrations → E-mail sending starts with "How e-mails are sent" (component `MailRelayStatus` from `/admin`, @@ -220,7 +248,7 @@ Routes (all three need the `admin` role: not logged in → 401, other role → 4 | `GET /api/iapl/mail-relay/status` | the transport and the stored state; `?refresh=1` asks the service | | `POST /api/iapl/mail-relay/connect` | enrol now; with `{ token }` store a token issued by hand | | `POST /api/iapl/mail-relay/disconnect` | give the token up | -| `POST /api/iapl/mail-relay/confirm` | **public** — the service's call-back. `404` and no change unless the site itself started an enrolment in the last 5 minutes; rate-limited (10 a minute per address, `mail.relay.confirmRateLimit`) | +| `POST /api/iapl/mail-relay/confirm` | **public** — the service's call-back. `404` and no change unless the site itself started an enrolment in the last 5 minutes; **refused** calls are rate-limited (10 a minute per address, `mail.relay.confirmRateLimit`) — a call that carries the nonce is never turned away by the limit, so junk from the same address cannot keep the site from enrolling | These are the first routes under `/api/iapl/`; the others stay under `/api/ipal/` until 2.0. The confirm path is fixed by the service for this product — a project cannot move it. For your own panel: @@ -283,7 +311,8 @@ message); "Connect again" asks at once. Other causes: `host-not-allowed` (not a | `kind` | — | the kind of a message nobody marked | | `accountMail` | `{ perAddress: 5, perVisitor: 10, windowMinutes: 60 }` | the site's own limit on account mail; `false` = none | | `confirmRateLimit` | `{ max: 10, windowMs: 60000 }` | calls to the public confirm route per address | -| `timeoutMs` | `30000` | one attempt of a send | +| `totalTimeoutMs` | `10000`; `30000` with files | everything one message may take — enrolment, attempts and waits together. Somebody waits for the request that sends the mail; after it the message is reported ("not confirmed" when an attempt was cut off). A number, or `{ plain, files }` | +| `timeoutMs` | `30000` | one attempt of a send; never more than what is left of `totalTimeoutMs` | | `retryBackoffMs` | `1000` | the wait before the next attempt when the service names none (times the attempt's number) | | `fetchImpl` | `fetch` | for tests | | `graphDeprecationWarning` (on `mail`) | `true` | `false` silences the start warning of a site on Microsoft Graph | @@ -307,6 +336,9 @@ the confirm path under the API route, `RELAY_SENDER_ADDRESS` the sender address panel's sender name and reply address when Site integrations exists. `relayAttachmentLimit(payload, options)` is its file limit. - **The confirm route alone:** `relayConfirmEndpoint()`, for a project that builds its own config without `iapl()`. + **Without that route in the config the site does not ask to be enrolled at all** (`mailAdapter()` without `iapl()`, + or `mailAdapter({ relay: {} })` beside `mail: { relay: false }`): the send reports `relay-refused` and says which + route is missing. A token from `relay.token` needs no route. - **Your own e-mail adapter:** `email:` in `buildConfig` is the project's and wins over everything here ("Your own e-mail adapter" below). @@ -519,7 +551,10 @@ to the client's address. The OAuth token is cached in the process until a minute The service names its limit (10 MB in all files of one message, 20 files, unless Intecion set other numbers for the site); the plugin reads it from the service and `mailAttachmentLimit(payload)` reports it. A message over the limit is refused before it is uploaded (`relay-too-large`). Programs and scripts are refused by file name -(`relay-attachment-refused`). Content must be a `Buffer` or a string — a stream or a file path is not carried. +(`relay-attachment-refused`). Content must be a `Buffer` or a string — a stream or a file path is not carried, and +such a message fails whole (`relay-error`). **Inline images** (`cid:` attachments) are carried as ordinary files: +the picture shows as an attachment and as a broken image in the text — link images by URL instead. Only the first +`replyTo` address is used; free headers (`List-Unsubscribe` among them) are dropped. The test e-mail's 10 MB file is at the limit: it shows whether the site's limit is the default. ### SMTP diff --git a/docs/security.md b/docs/security.md index f8c00ab..66351b1 100644 --- a/docs/security.md +++ b/docs/security.md @@ -1006,16 +1006,19 @@ 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:///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 | +| **A token of another site** (pasted into the access-key field, stored by a script) | refused: the service is asked which host the token is for before it is stored or used; a foreign one is not saved, not used, not revoked | +| **A token read from a database dump** | **works from the same server** (a staging site on the machine production runs on shares its outgoing address) — which is why the store is tied to its host, above. From another server it does not work: 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: ` 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 | +| **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 — a `200`, or a refusal the service gives after it has checked the token; no answer, an error page or `rate-limited` prove nothing and leave both as they are. **Refused** calls are rate-limited per address (10 a minute, `mail.relay.confirmRateLimit`); the nonce is looked up first, so junk from the address the service shares with others cannot keep the site's own enrolment out. A stranger who calls it learns nothing and changes nothing | | **Who can start an enrolment** | the server itself (a send without a token) and an admin ("Connect again"). The three state routes need the `admin` role and answer with states only | | **A site taken over by an attacker with admin rights** | can send mail through the service under any sender name the service's check lets through, within the limits — as it could through the site's SMTP server. Intecion sees the host on every mail and can suspend the site (`relay-suspended`) | | **Visitors** | cannot reach the service: only the server calls it. What a visitor can trigger is a form's mail (rate limit, Turnstile) and "forgot password" — limited by the site per address and per visitor (`mail.relay.accountMail`), because the service does not limit account mail per address | | **A subject or name typed by a visitor** | line breaks, control characters, direction marks and other invisible characters are removed before the message leaves (`cleanSubject`); recipients are reduced to bare addresses; a message has no header field | Turn off: `iapl({ mail: { relay: false } })` — no route, no outbound call, no token. Give the token up: -"Disconnect" in the panel (`disconnectRelay`), which revokes it on the service at once. +"Disconnect" in the panel (`disconnectRelay`), which revokes it on the service — at once when the service answers; +when it cannot be reached the site stops using the token, the panel says the disconnection is not confirmed, and +the token stays valid at the service until "Disconnect" is pressed again and answered. ## Dashboard alerts by role (`dashboardAlerts`) diff --git a/reference/.agents/skills/iapl-debug/SKILL.md b/reference/.agents/skills/iapl-debug/SKILL.md index 2a29c20..1f9199b 100644 --- a/reference/.agents/skills/iapl-debug/SKILL.md +++ b/reference/.agents/skills/iapl-debug/SKILL.md @@ -110,7 +110,11 @@ through this procedure. Ask only when you are missing something you cannot get y | `relay-too-large` / `relay-attachment-refused` | files over the service's limit (10 MB a message); a program or script as attachment | lower the File field's maximum (`iapl-form`); other file types; SMTP for larger files | | `relay-recipient-suppressed` | one recipient's mailbox bounced or complained before (for any site); nothing was sent to anybody | correct the address in the form's Emails tab; ask Intecion to clear the address | | `relay-unreachable` | the service or its mail back end failed, or the server cannot reach `webservices.intecion.net` | `curl -s https://webservices.intecion.net/mail/health` from the server → `{"ok":true}`; if it persists: SMTP, and tell Intecion | -| `relay-not-confirmed` / "may have been sent" | no answer from the service (time-out, connection lost) | check the recipient's mailbox **before** sending again; the same message sent again cannot double | +| `relay-not-confirmed` / "may have been sent" | no answer of the service: a time-out, a lost connection, an error page of a proxy in front, or the message's time budget (10 s, 30 s with files) ran out while an attempt was open | check the recipient's mailbox **before** sending again — a repeat after a restart or from another instance is a new message and can double. A service that hangs for everybody: SMTP meanwhile, tell Intecion | +| state block: "the disconnection is not confirmed" | "Disconnect" could not reach the service: the site stopped sending, the token still works there | press "Disconnect" again when the service answers | +| "This access key belongs to another site" | a token issued for another host was pasted | ask Intecion for a token for this host | +| `relay-refused`, cause `client-no-route` | the config has no `POST /api/iapl/mail-relay/confirm`: `mailAdapter()` without `iapl()`, or beside `mail: { relay: false }` | use the plugin option, or add `relayConfirmEndpoint()` to `endpoints` | +| log: "The SMTP settings in Site integrations are incomplete" | server, user name or password is missing, so the mail service carries the mail | complete the three fields, or empty them | | `relay-error` | the service refused the request as wrong (a bug), or the message has no valid recipient or no body | server log line `[iapl] mail service: …` → `iapl-plugin-gap` | | the mail arrives under the site's host instead of the client's name | the service did not accept "Sender name" (an address, a bank or provider name, mixed scripts, over 64 characters) — the state block says which name was used | another name; an honest name that is still replaced → Intecion | | replies to the site's mail are lost | "Sender address" is empty: the service's own address has no mailbox | fill it in (doctor: `mail-reply-address`) | diff --git a/reference/.agents/skills/iapl-upgrade/SKILL.md b/reference/.agents/skills/iapl-upgrade/SKILL.md index f0e7bbc..419c46b 100644 --- a/reference/.agents/skills/iapl-upgrade/SKILL.md +++ b/reference/.agents/skills/iapl-upgrade/SKILL.md @@ -554,13 +554,16 @@ builds; the panel opens; the old commands (`pnpm exec ipal-doctor`) still run. **→ 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 +1. **Every site:** no schema change, no migration, no import-map change. `pnpm payload generate:types` gives a small diff + (four field descriptions of Site integrations): run it and commit, or a CI that compares types fails. The e-mail tab gains the block "How e-mails are sent" and new wording ("Automatic", "Own SMTP server"). 2. **Which case** — Site integrations → E-mail sending, and the Coolify env: - **SMTP filled in** (server, user name, password): nothing changes, the site contacts nobody. Done. - **`GRAPH_*` set:** mail as before; one deprecation warning per start, doctor warning `mail-graph-deprecated`. Do **not** remove the variables in passing — moving the site is the owner's decision (email.md "Moving off Microsoft Graph"). Note: with `GRAPH_*` set and SMTP filled in, the panel's choice decides as before. + - **SMTP half filled in** (a server or user name without the rest; refused until now): mail now goes through the + mail service, with one log line and a hint in the panel — complete or empty the fields. - **Neither** (mail failed with "not configured" until now): **on its next e-mail the site contacts `webservices.intecion.net` with its host and the plugin version**, receives its own token through the new public route `POST /api/iapl/mail-relay/confirm`, and from then on sends from `notification@webservices.intecion.net` diff --git a/src/globals/SiteIntegrations/components/MailRelayStatus.tsx b/src/globals/SiteIntegrations/components/MailRelayStatus.tsx index 56a984e..0dda037 100644 --- a/src/globals/SiteIntegrations/components/MailRelayStatus.tsx +++ b/src/globals/SiteIntegrations/components/MailRelayStatus.tsx @@ -3,7 +3,7 @@ import { useConfig, useTranslation } from '@payloadcms/ui' import { useCallback, useEffect, useState } from 'react' -import { iaplT } from '../../../modules/admin-i18n/t.js' +import { formatDateTime, iaplT } from '../../../modules/admin-i18n/t.js' import { RELAY_CONNECT_PATH, RELAY_DISCONNECT_PATH, RELAY_STATUS_PATH } from '../../../modules/email/relay/constants.js' type Window = { limit: number; remaining: number } @@ -15,13 +15,16 @@ type State = { relay?: { connected?: boolean disconnected?: boolean + lastFailure?: { at: string; code: string } nameReplaced?: { asked: string; used: string } quota?: { day?: Window; hour?: Window } + revokePending?: boolean senderAddress?: string state?: 'active' | 'pending' | 'suspended' tokenSource?: string } | null replyAddress?: null | string + smtpIncomplete?: boolean transport?: 'graph' | 'none' | 'relay' | 'smtp' } @@ -40,7 +43,7 @@ const warn = { ...line, color: 'var(--theme-warning-600, #b45309)' } as const * own; a project's own panel can import it from `/admin`. Texts: `mailRelay*` keys. */ export const MailRelayStatus = () => { - const { t } = useTranslation() + const { i18n, t } = useTranslation() const { config } = useConfig() const api = config.routes?.api ?? '/api' const text = (key: Parameters[1], vars?: Record) => iaplT(t as never, key, vars) @@ -81,7 +84,7 @@ export const MailRelayStatus = () => { } const relay = state.relay const onRelay = state.transport === 'relay' - const relayState = !relay ? '' : relay.disconnected ? text('mailRelayStateDisconnected') + const relayState = !relay ? '' : relay.disconnected ? text(relay.revokePending ? 'mailRelayDisconnectUnconfirmed' : 'mailRelayStateDisconnected') // why the service does not take this site: a refused enrolment, or a hand-issued token that stopped working : state.refusalText ? state.refusalText : !relay.connected ? text('mailRelayStateNotConnected') @@ -103,6 +106,8 @@ export const MailRelayStatus = () => { <>

{relayState}

{state.replyAddress ? text('mailRelayRepliesTo', { address: state.replyAddress }) : text('mailRelayNoReplyAddress')}

+ {state.smtpIncomplete ?

{text('mailRelaySmtpIncomplete')}

: null} + {relay.lastFailure ?

{text('mailRelayLastFailure', { code: relay.lastFailure.code, date: formatDateTime(relay.lastFailure.at, i18n.language) })}

: null} {relay.nameReplaced ?

{text('mailRelayNameReplaced', { asked: relay.nameReplaced.asked, used: relay.nameReplaced.used })}

: null} {relay.quota?.hour && relay.quota.day ? (

{text('mailRelayQuota', { day: relay.quota.day.remaining, hour: relay.quota.hour.remaining })}

@@ -115,7 +120,7 @@ export const MailRelayStatus = () => { - {relay.connected ? ( + {relay.connected || relay.revokePending ? (