diff --git a/docs/CHANGELOG.md b/docs/CHANGELOG.md
index 2971a78..f4242e2 100644
--- a/docs/CHANGELOG.md
+++ b/docs/CHANGELOG.md
@@ -51,11 +51,12 @@ once there are more than 20.
> **5. E-mail — nothing to do, one thing to know.** "Sending method" in Site integrations → E-mail sending is a
> choice again: IWSN (built-in), Own SMTP server, Microsoft Graph (deprecated). **Upgrading writes nothing and
> loses no mail:** the field shows the method the site sends through today as selected (no SMTP server → IWSN; an
-> SMTP server → Own SMTP server; `GRAPH_*` → Microsoft Graph), and the site keeps sending that way. **The first save
-> of Site integrations stores that choice; from then on the site sends that way only.** If the chosen method cannot
+> SMTP server → Own SMTP server; `GRAPH_*` → Microsoft Graph), and the site keeps sending that way. **Nothing changes
+> until somebody picks another option:** saving the page with the method shown stores no choice. A different option
+> picked and saved is stored, and from then on the site sends that way only.** If the chosen method cannot
> be used — "Own SMTP server" without server, user name and password, "Microsoft Graph" on a server without
> `GRAPH_*` — e-mails **fail and the panel says so; they are not sent another way** (in 1.17.0 they would have gone
-> through SMTP or IWSN). So after the upgrade: open the tab, check that the method shown is the one meant, save.
+> through SMTP or IWSN). The panel warns while the option is being picked, before the save.
> **Postgres / SQLite projects: create and apply one migration** (`pnpm payload migrate:create`; the new field
> `emailMethod` is a column) in the same deploy. Without it the site still sends its mail the old way and one loud
> log line says so, but the Site integrations page of the panel does not open. MongoDB: nothing.
diff --git a/docs/agent/AGENT.md b/docs/agent/AGENT.md
index f2c6008..783a860 100644
--- a/docs/agent/AGENT.md
+++ b/docs/agent/AGENT.md
@@ -1298,14 +1298,16 @@ one migration** (`pnpm payload migrate:create`, applied at container start); bef
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`,
+service → nothing. Saving with the method shown stores no choice: only picking another option does (the owner's
+rule: nothing changes until somebody picks another option); `setMailMethod` fixes it from code. The state block warns
+while an unusable option is picked, before the save. From code: `getMailMethod`,
`setMailMethod(payload, 'relay' | 'smtp' | 'graph' | null)`, `resolveMailMethod` (`ResolvedMailMethod`,
`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".
+reports `mail-method` info (nothing picked yet) or nothing (picked and usable). `mail: { relay: false }` removes the option "IWSN".
**What the site needs for the mail service** — check each one:
diff --git a/docs/agent/skills/iapl-debug/SKILL.md b/docs/agent/skills/iapl-debug/SKILL.md
index 14e7686..bcec0df 100644
--- a/docs/agent/skills/iapl-debug/SKILL.md
+++ b/docs/agent/skills/iapl-debug/SKILL.md
@@ -102,7 +102,7 @@ through this procedure. Ask only when you are missing something you cannot get y
| emails are not sent | no `email: mailAdapter()` / empty Emails tab of the form / the transport fails | Site integrations → E-mail sending: read the block "How e-mails are sent" and the banner's code, then **Send test e-mail**; rows below; email.md |
| e-mails are not sent; state block: "Your SMTP server is chosen, but its settings are incomplete" / "Microsoft Graph is chosen, but it is not set up on this server" (status `smtp-incomplete` / `graph-not-set-up`, doctor `mail-method` error) | the chosen "Sending method" cannot be used, and since 1.17.1 nothing is sent another way | fill in server, user name and password / set the `GRAPH_*` variables — or choose another method (IWSN needs nothing) and save |
| Site integrations does not open after the upgrade to 1.17.1 (Postgres / SQLite); log: "the column for \"emailMethod\" … is missing"; doctor `mail-method` error | the migration that adds the column has not run (mail still leaves the old way) | `pnpm payload migrate:create`, commit, apply at container start |
-| the site switched how it sends after a field or a variable changed | nobody has chosen the "Sending method" yet (doctor `mail-method` info): the site still picks by the order of 1.17.0 | Site integrations → E-mail sending: check the method shown, save |
+| the site switched how it sends after a field or a variable changed | nobody has chosen the "Sending method" yet (doctor `mail-method` info): the site still picks by the order of 1.17.0 | nothing, if that is wanted (the owner's rule: no change until another option is picked); to fix it: pick the method (another option, then this one) or `setMailMethod(payload, '')` |
| 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:///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` |
diff --git a/docs/agent/skills/iapl-setup/SKILL.md b/docs/agent/skills/iapl-setup/SKILL.md
index 1216b54..1bf3602 100644
--- a/docs/agent/skills/iapl-setup/SKILL.md
+++ b/docs/agent/skills/iapl-setup/SKILL.md
@@ -661,7 +661,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). "Sending method" stays **IWSN (built-in)**; choose **Own SMTP server** and fill in its fields **only** when the client asked
- for its own server — what is chosen is what is used, an incomplete SMTP server sends nothing. Save the tab once so the choice is stored. On the production domain: the block "How e-mails are sent" must say "Connected to IWSN" ("waiting for approval": while the service runs with enrolment "pending" (from its launch until Intecion switches to open enrolment), every new site waits for approval — ask Intecion to approve the host; under open enrolment it is the exception; the real domain enrols by itself at launch although the site was connected on its development address — nothing to press; "The data comes from another site" = the site is non-public (its host matches `developmentHosts`, built in `*.dev.netscale.pl`, or `IAPL_NOINDEX=1`) and holds a copy of another site's data: press "Connect again" only if the copy should send — on the production domain it means `IAPL_NOINDEX` was left set. A development address under `*.dev.netscale.pl` needs nothing; a staging or test copy on any other host must have its host in `iapl({ developmentHosts: […] })` (an array of host patterns: a single string, an empty entry or a lone `*` stops the start) or `IAPL_NOINDEX=1`, or it mails the real addresses in its data), then **Send test e-mail** → "through IWSN". Turnstile (for testing site
+ for its own server — what is chosen is what is used, an incomplete SMTP server sends nothing. A new site sends through IWSN with nothing picked; picking another option and saving stores it (the panel warns before the save when its settings are incomplete). On the production domain: the block "How e-mails are sent" must say "Connected to IWSN" ("waiting for approval": while the service runs with enrolment "pending" (from its launch until Intecion switches to open enrolment), every new site waits for approval — ask Intecion to approve the host; under open enrolment it is the exception; the real domain enrols by itself at launch although the site was connected on its development address — nothing to press; "The data comes from another site" = the site is non-public (its host matches `developmentHosts`, built in `*.dev.netscale.pl`, or `IAPL_NOINDEX=1`) and holds a copy of another site's data: press "Connect again" only if the copy should send — on the production domain it means `IAPL_NOINDEX` was left set. A development address under `*.dev.netscale.pl` needs nothing; a staging or test copy on any other host must have its host in `iapl({ developmentHosts: […] })` (an array of host patterns: a single string, an empty entry or a lone `*` stops the start) or `IAPL_NOINDEX=1`, or it mails the real addresses in its data), 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.
diff --git a/docs/agent/skills/iapl-upgrade/SKILL.md b/docs/agent/skills/iapl-upgrade/SKILL.md
index d96d899..355319d 100644
--- a/docs/agent/skills/iapl-upgrade/SKILL.md
+++ b/docs/agent/skills/iapl-upgrade/SKILL.md
@@ -679,8 +679,9 @@ PROGRAMISTA §6, items 73–75; email.md; AGENT.md §7.2) — nothing to run; re
import-map change; `pnpm payload generate:types` gives a diff (the field `emailMethod`): run it and commit.
2. After the deploy open Site integrations → E-mail sending. "Sending method" shows the method the site sends through
today as selected: **IWSN (built-in)** (no SMTP server), **Own SMTP server**, or **Microsoft Graph (deprecated)**
- (`GRAPH_*` on the server). Check it is the one meant, **save**, send a test e-mail: the answer names the method.
- Until that save the site keeps the order of 1.17.0 and `iapl-doctor --deep` notes it (`mail-method`, info).
+ (`GRAPH_*` on the server). Nothing to save: the site keeps sending exactly as before **until somebody picks another
+ option** (saving with the shown method stores nothing); `iapl-doctor --deep` notes it (`mail-method`, info). Send a
+ test e-mail: the answer names the method.
3. From the save on what is chosen is what is used: "Own SMTP server" with an incomplete server, or "Microsoft Graph"
without `GRAPH_*`, sends **nothing** and says so (state block, `mail-method` error) — no fallback to another method.
Tell the owner before changing the method on a live site.
diff --git a/docs/email.md b/docs/email.md
index 4b49588..6fad267 100644
--- a/docs/email.md
+++ b/docs/email.md
@@ -94,9 +94,18 @@ The method follows the order of 1.17.0, the field shows it **as selected**, and
| half an SMTP set-up, no `GRAPH_*` | IWSN (built-in), with the hint "The SMTP settings below are incomplete" | through the service, as in 1.17.0 |
| a new site | IWSN (built-in) | through the service |
-**The first save of Site integrations stores what the form shows** (the form always sends the field), and from
-then on the method is fixed. The state block says "Nobody has chosen the sending method yet, so the site picked
-this one. Save this page to keep it." until then, and the doctor's deep run notes it (`mail-method`, info). A script
+**Nothing changes until somebody picks another option.** Saving Site integrations with the method shown stores no
+choice — the site keeps sending exactly as before and keeps following what is filled in, as in 1.17.0 (owner's rule,
+2026-11-26). Picking a **different** option and saving stores it; from then on the method is fixed (a save that keeps
+it keeps it). The state block says "The site sends the way it did before. It changes only when you pick another
+sending method." meanwhile, and the doctor's deep run notes it (`mail-method`, info). To fix the method shown without
+picking another, a script calls `setMailMethod(payload, 'relay')`.
+
+**A warning before the save.** The state block reads the form as it is being edited: "Own SMTP server" picked with
+server, user name or password empty says "Fill in server, user name and password below. If you save without them,
+e-mails will not be sent."; "Microsoft Graph" picked on a server without `GRAPH_*` says the same for Graph. After the
+save the block reloads and shows the saved state (the error above, if it was saved anyway). Saving is not refused:
+an admin may set the method first and the server after. A script
of before 1.17.1 that writes `emailTransport` alone still means what it meant: it puts the site back on the order
above (write `emailMethod` to choose).
diff --git a/reference/.agents/skills/iapl-debug/SKILL.md b/reference/.agents/skills/iapl-debug/SKILL.md
index 14e7686..bcec0df 100644
--- a/reference/.agents/skills/iapl-debug/SKILL.md
+++ b/reference/.agents/skills/iapl-debug/SKILL.md
@@ -102,7 +102,7 @@ through this procedure. Ask only when you are missing something you cannot get y
| emails are not sent | no `email: mailAdapter()` / empty Emails tab of the form / the transport fails | Site integrations → E-mail sending: read the block "How e-mails are sent" and the banner's code, then **Send test e-mail**; rows below; email.md |
| e-mails are not sent; state block: "Your SMTP server is chosen, but its settings are incomplete" / "Microsoft Graph is chosen, but it is not set up on this server" (status `smtp-incomplete` / `graph-not-set-up`, doctor `mail-method` error) | the chosen "Sending method" cannot be used, and since 1.17.1 nothing is sent another way | fill in server, user name and password / set the `GRAPH_*` variables — or choose another method (IWSN needs nothing) and save |
| Site integrations does not open after the upgrade to 1.17.1 (Postgres / SQLite); log: "the column for \"emailMethod\" … is missing"; doctor `mail-method` error | the migration that adds the column has not run (mail still leaves the old way) | `pnpm payload migrate:create`, commit, apply at container start |
-| the site switched how it sends after a field or a variable changed | nobody has chosen the "Sending method" yet (doctor `mail-method` info): the site still picks by the order of 1.17.0 | Site integrations → E-mail sending: check the method shown, save |
+| the site switched how it sends after a field or a variable changed | nobody has chosen the "Sending method" yet (doctor `mail-method` info): the site still picks by the order of 1.17.0 | nothing, if that is wanted (the owner's rule: no change until another option is picked); to fix it: pick the method (another option, then this one) or `setMailMethod(payload, '')` |
| 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:///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` |
diff --git a/reference/.agents/skills/iapl-setup/SKILL.md b/reference/.agents/skills/iapl-setup/SKILL.md
index 1216b54..1bf3602 100644
--- a/reference/.agents/skills/iapl-setup/SKILL.md
+++ b/reference/.agents/skills/iapl-setup/SKILL.md
@@ -661,7 +661,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). "Sending method" stays **IWSN (built-in)**; choose **Own SMTP server** and fill in its fields **only** when the client asked
- for its own server — what is chosen is what is used, an incomplete SMTP server sends nothing. Save the tab once so the choice is stored. On the production domain: the block "How e-mails are sent" must say "Connected to IWSN" ("waiting for approval": while the service runs with enrolment "pending" (from its launch until Intecion switches to open enrolment), every new site waits for approval — ask Intecion to approve the host; under open enrolment it is the exception; the real domain enrols by itself at launch although the site was connected on its development address — nothing to press; "The data comes from another site" = the site is non-public (its host matches `developmentHosts`, built in `*.dev.netscale.pl`, or `IAPL_NOINDEX=1`) and holds a copy of another site's data: press "Connect again" only if the copy should send — on the production domain it means `IAPL_NOINDEX` was left set. A development address under `*.dev.netscale.pl` needs nothing; a staging or test copy on any other host must have its host in `iapl({ developmentHosts: […] })` (an array of host patterns: a single string, an empty entry or a lone `*` stops the start) or `IAPL_NOINDEX=1`, or it mails the real addresses in its data), then **Send test e-mail** → "through IWSN". Turnstile (for testing site
+ for its own server — what is chosen is what is used, an incomplete SMTP server sends nothing. A new site sends through IWSN with nothing picked; picking another option and saving stores it (the panel warns before the save when its settings are incomplete). On the production domain: the block "How e-mails are sent" must say "Connected to IWSN" ("waiting for approval": while the service runs with enrolment "pending" (from its launch until Intecion switches to open enrolment), every new site waits for approval — ask Intecion to approve the host; under open enrolment it is the exception; the real domain enrols by itself at launch although the site was connected on its development address — nothing to press; "The data comes from another site" = the site is non-public (its host matches `developmentHosts`, built in `*.dev.netscale.pl`, or `IAPL_NOINDEX=1`) and holds a copy of another site's data: press "Connect again" only if the copy should send — on the production domain it means `IAPL_NOINDEX` was left set. A development address under `*.dev.netscale.pl` needs nothing; a staging or test copy on any other host must have its host in `iapl({ developmentHosts: […] })` (an array of host patterns: a single string, an empty entry or a lone `*` stops the start) or `IAPL_NOINDEX=1`, or it mails the real addresses in its data), 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.
diff --git a/reference/.agents/skills/iapl-upgrade/SKILL.md b/reference/.agents/skills/iapl-upgrade/SKILL.md
index d96d899..355319d 100644
--- a/reference/.agents/skills/iapl-upgrade/SKILL.md
+++ b/reference/.agents/skills/iapl-upgrade/SKILL.md
@@ -679,8 +679,9 @@ PROGRAMISTA §6, items 73–75; email.md; AGENT.md §7.2) — nothing to run; re
import-map change; `pnpm payload generate:types` gives a diff (the field `emailMethod`): run it and commit.
2. After the deploy open Site integrations → E-mail sending. "Sending method" shows the method the site sends through
today as selected: **IWSN (built-in)** (no SMTP server), **Own SMTP server**, or **Microsoft Graph (deprecated)**
- (`GRAPH_*` on the server). Check it is the one meant, **save**, send a test e-mail: the answer names the method.
- Until that save the site keeps the order of 1.17.0 and `iapl-doctor --deep` notes it (`mail-method`, info).
+ (`GRAPH_*` on the server). Nothing to save: the site keeps sending exactly as before **until somebody picks another
+ option** (saving with the shown method stores nothing); `iapl-doctor --deep` notes it (`mail-method`, info). Send a
+ test e-mail: the answer names the method.
3. From the save on what is chosen is what is used: "Own SMTP server" with an incomplete server, or "Microsoft Graph"
without `GRAPH_*`, sends **nothing** and says so (state block, `mail-method` error) — no fallback to another method.
Tell the owner before changing the method on a live site.
diff --git a/reference/e2e/mail-relay.spec.ts b/reference/e2e/mail-relay.spec.ts
index 7e3e142..076af49 100644
--- a/reference/e2e/mail-relay.spec.ts
+++ b/reference/e2e/mail-relay.spec.ts
@@ -90,9 +90,12 @@ test.describe('the mail service', () => {
await page.locator('.rs__option', { hasText: /Own SMTP server|Własny serwer SMTP/ }).click()
await expect(page.locator('#field-smtpHost')).toBeVisible()
await expect(page.locator('#field-smtpUser')).toBeVisible()
+ // picked, not saved, and the server is empty: the block warns at once
+ await expect(page.locator('[data-mail-method-warning="smtp"]')).toBeVisible()
await method.locator('.rs__control').click()
await page.locator('.rs__option', { hasText: /IWSN/ }).click()
await expect(page.locator('#field-smtpHost')).toHaveCount(0)
+ await expect(page.locator('[data-mail-method-warning]')).toHaveCount(0)
// (Payload takes the login cookie only from the site's own origin, so the request says where it comes from)
const status = await page.request.get('/api/iapl/mail-relay/status', { headers: { origin: baseURL! } })
diff --git a/src/globals/SiteIntegrations/components/MailRelayStatus.tsx b/src/globals/SiteIntegrations/components/MailRelayStatus.tsx
index 4c86eea..d51d5d0 100644
--- a/src/globals/SiteIntegrations/components/MailRelayStatus.tsx
+++ b/src/globals/SiteIntegrations/components/MailRelayStatus.tsx
@@ -1,15 +1,17 @@
'use client'
-import { useConfig, useTranslation } from '@payloadcms/ui'
+import { useConfig, useFormFields, useTranslation } from '@payloadcms/ui'
import { useCallback, useEffect, useState } from 'react'
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'
+import { SECRET_CLEAR } from '../../../modules/secrets/constants.js'
type Window = { limit: number; remaining: number }
type State = {
accessKeyField?: boolean
error?: string
+ graphReady?: boolean
message?: string
methodChosen?: boolean
methodProblem?: 'graph-not-set-up' | 'smtp-incomplete'
@@ -76,9 +78,18 @@ export const MailRelayStatus = () => {
[api, t],
)
+ // the form as it is now — before it is saved: a method picked that cannot send is said at once
+ const formMethod = useFormFields(([f]) => f.emailMethod?.value) as string | undefined
+ const formHost = useFormFields(([f]) => f.smtpHost?.value) as string | undefined
+ const formUser = useFormFields(([f]) => f.smtpUser?.value) as string | undefined
+ // (a stored password arrives as the mask: set; "Remove the stored value" is SECRET_CLEAR: not set)
+ const formPassword = useFormFields(([f]) => f.smtpPassword?.value) as string | undefined
+ const savedAt = useFormFields(([f]) => f.updatedAt?.value) as string | undefined
+
+ // on load, and again after every save of the page: the state block says what the saved settings do
useEffect(() => {
void call(RELAY_STATUS_PATH)
- }, [call])
+ }, [call, savedAt])
const post = (path: string, body?: object) =>
call(path, { body: body ? JSON.stringify(body) : undefined, headers: body ? { 'Content-Type': 'application/json' } : undefined, method: 'POST' }, true)
@@ -106,8 +117,13 @@ export const MailRelayStatus = () => {
: state.transport === 'graph' ? text('mailRelayTransportGraph')
: text(relay ? 'mailRelayTransportNone' : 'mailRelayOff')}
+ {formMethod === 'smtp' && !(formHost?.trim() && formUser?.trim() && formPassword && formPassword !== SECRET_CLEAR) && !(state.methodProblem === 'smtp-incomplete' && state.transport === 'smtp') ? (
+ {text('mailMethodSmtpIncompleteForm')}
+ ) : formMethod === 'graph' && state.graphReady === false && state.methodProblem !== 'graph-not-set-up' ? (
+ {text('mailMethodGraphNotSetUpForm')}
+ ) : null}
{state.methodProblem ? (
- {text(state.methodProblem === 'graph-not-set-up' ? 'mailMethodGraphNotSetUp' : 'mailMethodSmtpIncomplete')}
+ {text(state.methodProblem === 'graph-not-set-up' ? 'mailMethodGraphNotSetUp' : 'mailMethodSmtpIncomplete')}
) : state.methodChosen === false && state.transport !== 'none' ? (
{text('mailMethodNotChosen')}
) : null}
diff --git a/src/globals/SiteIntegrations/index.ts b/src/globals/SiteIntegrations/index.ts
index 870338d..3c1d2b4 100644
--- a/src/globals/SiteIntegrations/index.ts
+++ b/src/globals/SiteIntegrations/index.ts
@@ -105,12 +105,17 @@ export function buildSiteIntegrations({
const refuse = (message: string): never => {
throw new ValidationError({ errors: [{ message, path: 'emailMethod' }], global: 'site-integrations' }, req.t)
}
- if (sent && data.emailMethod !== null && data.emailMethod !== undefined) {
+ // the owner's rule: a site keeps sending the way it does now until somebody picks ANOTHER option — a save that
+ // sends the method already shown, while nothing is stored, stores nothing
+ const shown = shownMailMethod({ ...(originalDoc ?? {}), emailMethod: stored } as never, mailRelay)
+ if (sent && stored === null && data.emailMethod === shown) {
+ data.emailMethod = null
+ } else if (sent && data.emailMethod !== null && data.emailMethod !== undefined) {
// anything but one of the three values (a number, a list, another word) is refused here: the database
// would answer with an error of its own, or take it
if (!isMailMethod(data.emailMethod)) {return refuse('This is not a sending method.')}
if (data.emailMethod === 'relay' && !mailRelay) {return refuse('This sending method is switched off for this site.')}
- if (shownMailMethod({ ...(originalDoc ?? {}), emailMethod: stored } as never, mailRelay) !== data.emailMethod) {
+ if (shown !== data.emailMethod) {
data.emailStatus = { checkedAt: null, code: null, message: null, since: null, state: null }
}
// the stored field of 1.6 – 1.17.0 follows where it can say it
diff --git a/src/modules/admin-i18n/texts/integrations.ts b/src/modules/admin-i18n/texts/integrations.ts
index bf9d1a9..31b5811 100644
--- a/src/modules/admin-i18n/texts/integrations.ts
+++ b/src/modules/admin-i18n/texts/integrations.ts
@@ -12,8 +12,10 @@ export const integrationsTexts = defineTexts({
// Intecion mail service: the state block on the e-mail tab (MailRelayStatus) and its routes
mailMethodGraphNotSetUp: 'Microsoft Graph is chosen, but it is not set up on this server. E-mails are not sent. Ask your administrator.',
- mailMethodNotChosen: 'Nobody has chosen the sending method yet, so the site picked this one. Save this page to keep it.',
+ mailMethodGraphNotSetUpForm: 'Microsoft Graph is not set up on this server. If you save this, e-mails will not be sent.',
+ mailMethodNotChosen: 'The site sends the way it did before. It changes only when you pick another sending method.',
mailMethodSmtpIncomplete: 'Your SMTP server is chosen, but its settings are incomplete. E-mails are not sent. Fill in server, user name and password.',
+ mailMethodSmtpIncompleteForm: 'Fill in server, user name and password below. If you save without them, e-mails will not be sent.',
mailRelayCheck: 'Check now',
mailRelayConnect: 'Connect again',
mailRelayConnected: `The site is connected to ${IWSN}.`,
@@ -138,8 +140,10 @@ export const integrationsTexts = defineTexts({
alertsUnknownError: 'Nieznany błąd.',
mailMethodGraphNotSetUp: 'Wybrano Microsoft Graph, ale nie jest on skonfigurowany na tym serwerze. E-maile nie są wysyłane. Zapytaj administratora.',
- mailMethodNotChosen: 'Nikt jeszcze nie wybrał sposobu wysyłki, więc witryna dobrała ten. Zapisz tę stronę, aby go zachować.',
+ mailMethodGraphNotSetUpForm: 'Microsoft Graph nie jest skonfigurowany na tym serwerze. Jeśli to zapiszesz, e-maile nie będą wysyłane.',
+ mailMethodNotChosen: 'Witryna wysyła tak jak dotąd. Zmieni to dopiero wybór innego sposobu wysyłki.',
mailMethodSmtpIncomplete: 'Wybrano Twój serwer SMTP, ale jego ustawienia są niepełne. E-maile nie są wysyłane. Uzupełnij serwer, nazwę użytkownika i hasło.',
+ mailMethodSmtpIncompleteForm: 'Uzupełnij poniżej serwer, nazwę użytkownika i hasło. Jeśli zapiszesz bez nich, e-maile nie będą wysyłane.',
mailRelayCheck: 'Sprawdź teraz',
mailRelayConnect: 'Połącz ponownie',
mailRelayConnected: `Witryna jest połączona z ${IWSN}.`,
diff --git a/src/modules/doctor/rules/mail.ts b/src/modules/doctor/rules/mail.ts
index 579b4b3..c3f789f 100644
--- a/src/modules/doctor/rules/mail.ts
+++ b/src/modules/doctor/rules/mail.ts
@@ -69,7 +69,7 @@ export const mailRules: DoctorRule[] = [
return [{ fix: 'set the four GRAPH_* variables on the server — or choose another sending method in Site integrations → E-mail sending (Microsoft Graph is deprecated and removed in 2.0)', message: '"Microsoft Graph" is the chosen sending method, but the GRAPH_* variables are missing on this server: e-mails are not sent (nothing is sent another way)', severity: 'error' }]
}
if (mail.methodChosen === false && mail.transport !== 'none') {
- return [{ fix: 'open Site integrations → E-mail sending, check "Sending method" and save: from then on the site sends that way only', message: `nobody has chosen the sending method yet: the site picks one from what is filled in (now: ${mail.transport === 'relay' ? 'the built-in service' : mail.transport === 'smtp' ? 'the SMTP server' : 'Microsoft Graph'}), and would switch by itself if that changed`, severity: 'info' }]
+ return [{ fix: 'nothing to do while it sends the way it should; to fix the method, pick it in Site integrations → E-mail sending (another option, or setMailMethod)', message: `nobody has picked a sending method: the site sends the way it did before the upgrade (now: ${mail.transport === 'relay' ? 'the built-in service' : mail.transport === 'smtp' ? 'the SMTP server' : 'Microsoft Graph'}) and follows what is filled in, as before`, severity: 'info' }]
}
return []
},
diff --git a/src/modules/email/relay/panel.ts b/src/modules/email/relay/panel.ts
index 3080a8b..4a12916 100644
--- a/src/modules/email/relay/panel.ts
+++ b/src/modules/email/relay/panel.ts
@@ -31,6 +31,8 @@ export type MailPanelState = {
accessKeyField?: boolean
/** The address the service calls this site back at. */
confirmUrl?: string
+ /** The four `GRAPH_*` variables are set on this server (whether "Microsoft Graph" could send). */
+ graphReady: boolean
/**
* An admin chose the method in effect ("Sending method" was saved). False: nobody has chosen yet, and the
* method follows the order of 1.17.0 until Site integrations is saved.
@@ -100,6 +102,7 @@ export async function mailPanelState(req: Pick, own:
return {
...(options?.accessKeyField === true ? { accessKeyField: true } : {}),
...(status?.host ? { confirmUrl: `https://${status.host}${api}${RELAY_CONFIRM_PATH}` } : {}),
+ graphReady: graphAvailable(),
methodChosen: method.explicit,
...(mailMethodColumnMissing() ? { methodColumnMissing: true } : {}),
...(method.problem ? { methodProblem: method.problem } : {}),
diff --git a/test/doctor.test.ts b/test/doctor.test.ts
index 9ab0496..7e83166 100644
--- a/test/doctor.test.ts
+++ b/test/doctor.test.ts
@@ -752,7 +752,8 @@ describe('e-mail: transport, the mail service, Graph, the confirm route', () =>
const open = await find({ methodChosen: false })
expect(open.map((f) => f.severity)).toEqual(['info'])
expect(open[0].message).toContain('the built-in service')
- expect(open[0].fix).toContain('save')
+ expect(open[0].message).toContain('the way it did before the upgrade')
+ expect(open[0].fix).toContain('nothing to do')
expect(await find({ methodChosen: true })).toEqual([])
// Postgres / SQLite whose 1.17.1 migration has not run
const column = await find({ methodChosen: false, methodColumnMissing: true })
diff --git a/test/mailMethodHttp.test.ts b/test/mailMethodHttp.test.ts
index 58060ca..f832a85 100644
--- a/test/mailMethodHttp.test.ts
+++ b/test/mailMethodHttp.test.ts
@@ -152,22 +152,50 @@ describe('upgrade, with no edit: the site shows the method it sends through toda
})
describe('the choice: what is chosen is what is used', () => {
- test('the first save of the panel\'s form stores what the form shows; the answer shows it; the stored field of 1.17.0 follows', async () => {
+ test('the owner\'s rule: saving without picking another option stores nothing and changes nothing; picking another one stores it', async () => {
+ // an upgraded site on the service: the form is saved as it is, twice — nothing is chosen, mail goes as before
+ await asStored({})
+ for (const change of [{}, { smtpFromName: 'Kancelaria Example' }]) {
+ const saved = await saveForm(change)
+ expect(saved.status).toBe(200)
+ expect(((await saved.json()) as { result: { emailMethod: string } }).result.emailMethod).toBe('relay')
+ expect(await getMailMethod(payload)).toBeNull()
+ }
+ expect(await state()).toMatchObject({ methodChosen: false, transport: 'relay' })
+ // …and it still follows what is filled in, as before (the old order): an SMTP server is filled in → SMTP
+ await payload.updateGlobal({ slug: 'site-integrations' as never, data: SMTP as never })
+ expect((await read()).emailMethod).toBe('smtp')
+ expect(await getMailMethod(payload)).toBeNull()
+ // a Graph site saved as it is stays a Graph site (the old order), with the variables
+ for (const name of GRAPH_ENV) {vi.stubEnv(name, 'x')}
+ await asStored({ emailTransport: 'graph' })
+ await saveForm({})
+ expect(await getMailMethod(payload)).toBeNull()
+ expect(await read()).toMatchObject({ emailMethod: 'graph', emailTransport: 'graph' })
+ for (const name of GRAPH_ENV) {vi.stubEnv(name, '')}
+ // picking ANOTHER option stores it, and the answer shows it; the stored field of 1.17.0 follows
await asStored({})
- const saved = await saveForm({ smtpFromName: 'Kancelaria Example' })
- expect(saved.status).toBe(200)
- expect(((await saved.json()) as { result: { emailMethod: string } }).result.emailMethod).toBe('relay')
- expect(await getMailMethod(payload)).toBe('relay')
- expect(await state()).toMatchObject({ methodChosen: true, transport: 'relay' })
- // a choice changed in the form
const changed = await saveForm({ emailMethod: 'graph' })
expect(((await changed.json()) as { result: { emailMethod: string; emailTransport: string } }).result).toMatchObject({ emailMethod: 'graph', emailTransport: 'graph' })
expect(await getMailMethod(payload)).toBe('graph')
- expect((await read()).emailMethod).toBe('graph')
+ // once chosen, a save that keeps it keeps it, and the method no longer follows what is filled in
+ await saveForm({ emailMethod: 'relay' })
+ expect(await getMailMethod(payload)).toBe('relay')
+ await saveForm({ smtpFromName: 'Kancelaria Example' })
+ expect(await getMailMethod(payload)).toBe('relay')
+ await payload.updateGlobal({ slug: 'site-integrations' as never, data: SMTP as never })
+ expect(await state()).toMatchObject({ methodChosen: true, transport: 'relay' })
await saveForm({ emailMethod: 'smtp' })
expect(await read()).toMatchObject({ emailMethod: 'smtp', emailTransport: 'smtp' })
})
+ test('the state block is told whether Graph could send, for its warning before the save', async () => {
+ await asStored({})
+ expect((await state()).graphReady).toBe(false)
+ for (const name of GRAPH_ENV) {vi.stubEnv(name, 'x')}
+ expect((await state()).graphReady).toBe(true)
+ })
+
test('"IWSN" chosen: the service carries the mail although an SMTP server is filled in and the GRAPH_* variables are set', async () => {
await asStored(SMTP)
await saveForm({ emailMethod: 'relay' })