E-mail: "Sending method" is an explicit choice - IWSN (built-in), Own SMTP server, Microsoft Graph (deprecated)

What is chosen is what is used. The choice is the stored field `emailMethod` of Site integrations (empty until
somebody chooses); `emailTransport` of 1.6 - 1.17.0 stays, hidden.

- no silent switch: a chosen method that cannot be used (SMTP incomplete, Graph without GRAPH_*) fails loudly
  - status smtp-incomplete / graph-not-set-up, state block, doctor mail-method - and nothing is sent another way
- upgrade writes nothing and loses no mail: until somebody chooses, the order of 1.17.0 applies and the field
  shows its result as selected; the first save of the panel's form stores the choice
- only the chosen method's fields are shown; the test e-mail names the method (Graph too)
- mail: { relay: false } does not offer "IWSN" (the stored values stay three: one SQL enum for every project)
- Postgres / SQLite: one migration (a column). Before it runs the plugin's readers read the global without the
  field, mail goes the old way, one loud log line and the doctor say what to do
- getMailMethod, setMailMethod, resolveMailMethod, readMailSettings, mailMethodColumnMissing exported
- tests on SQLite, Postgres and MongoDB, with and without the migration; docs, AGENT.md, skills, changelog

Co-Authored-By: Claude Fable 5.2 <[email protected]>
This commit is contained in:
Radosław Smoliński
2026-11-26 22:39:03 +01:00
co-authored by Claude Fable 5.2
parent c6841a1674
commit ee8ea42956
26 changed files with 376 additions and 138 deletions
+7 -4
View File
@@ -1292,14 +1292,17 @@ banner that is already in every import map). **Do not** add `nodemailer`, `resen
**How a send is routed** — by the admin's choice, Site integrations → E-mail sending → **"Sending method"**: "IWSN
(built-in)" (the mail service), "Own SMTP server", "Microsoft Graph (deprecated)". What is chosen is what is used;
a choice that cannot be used (SMTP incomplete, Graph without `GRAPH_*`) **fails loudly and nothing is sent another
way** (state block, status `smtp-incomplete` / `graph-not-set-up`, doctor `mail-method`). The choice is kept in
`payload-kv` (`MAIL_METHOD_KV_KEY`); the panel's field `emailMethod` is virtual, so **no schema change and no
migration**. Until somebody chooses (an upgraded site, a new site) the order of 1.17.0 applies and the field shows
way** (state block, status `smtp-incomplete` / `graph-not-set-up`, doctor `mail-method`). The choice is the stored field
`emailMethod` (`relay` / `smtp` / `graph`; empty until somebody chooses) — **MongoDB: nothing to run; Postgres / SQLite:
one migration** (`pnpm payload migrate:create`, applied at container start); before it runs the site keeps sending the
old way, the Site integrations page does not open, and `iapl-doctor --deep` reports `mail-method` (error). Until somebody chooses (an upgraded site, a new site) the order of 1.17.0 applies and the field shows
its result as selected (`resolveMailTransport`, type `MailTransport`): Graph when `emailTransport` is `graph` and
`GRAPH_*` is set → SMTP when server, user name and password are filled in → Graph when `GRAPH_*` is set → the mail
service → nothing. The first save of Site integrations stores the choice. From code: `getMailMethod`,
`setMailMethod(payload, 'relay' | 'smtp' | 'graph' | null)`, `resolveMailMethod` (`ResolvedMailMethod`,
`MailMethodProblem`), `MailMethod`, `MAIL_METHODS`, `isMailMethod`; or `updateGlobal` with `emailMethod`. Seeds that
`MailMethodProblem`), `MailMethod`, `MAIL_METHODS`, `isMailMethod`, `readMailSettings` / `STORED_MAIL_METHOD_CONTEXT`
(a read with the value as stored — an ordinary read shows the method in effect), `mailMethodColumnMissing`; or
`updateGlobal` with `emailMethod`. Seeds that
set up mail write `emailMethod`, not `emailTransport`. **Verify:** the state block names the method; **Send test
e-mail** answers "through IWSN" / "through your SMTP server" / "through Microsoft Graph"; `iapl-doctor --deep`
reports no `mail-method` finding after the first save. `mail: { relay: false }` removes the option "IWSN".