Mail relay: review of 7d766b6 — R-1 to R-12, four mutations, two sentences
- 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 <[email protected]>
This commit is contained in:
co-authored by
Claude Fable 5.2
parent
0ee74ab2a4
commit
a2b07b1dc1
+40
-5
@@ -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
|
||||
|
||||
Reference in New Issue
Block a user