WIP: form attachments docs (forms, email, security, storage, deployment, notifications), honeypot value sent
Co-Authored-By: Claude Fable 5.2 <[email protected]>
This commit is contained in:
co-authored by
Claude Fable 5.2
parent
701bb420c1
commit
344574d6bd
+80
-6
@@ -139,8 +139,9 @@ [email protected] # one mailbox for all projects
|
||||
(no name → the `from` field is omitted, Graph uses the mailbox's default name),
|
||||
- `smtpFromAddress` → **Reply-To** (unless the message has its own `replyTo`).
|
||||
|
||||
Options `graphAdapter({ fallbackFromAddress, fallbackFromName })` — only placeholders
|
||||
Payload requires at startup.
|
||||
Options `graphAdapter({ fallbackFromAddress, fallbackFromName, largeAttachments, cleanupDelaysMs })` —
|
||||
the first two are placeholders Payload requires at startup; the other two are for attachments ("Attachments" below).
|
||||
`fetchImpl` is for tests.
|
||||
|
||||
### Wiring — choosing the transport (recommended: `mailAdapter`)
|
||||
|
||||
@@ -188,9 +189,80 @@ email: process.env.GRAPH_CLIENT_ID ? graphAdapter() : panelSmtpAdapter()
|
||||
The adapter does **not** send from the address in the panel — From is always the `GRAPH_SENDER` address
|
||||
(only the display name changes), and `smtpFromAddress` from the panel goes into
|
||||
Reply-To. So Exchange does not need Send-As on other domains; replies go
|
||||
to the client's address. The OAuth token is fetched on every send (no cache),
|
||||
to the client's address. The OAuth token is cached in the process until a minute before it expires,
|
||||
`saveToSentItems: false`.
|
||||
|
||||
## Attachments
|
||||
|
||||
`payload.sendEmail({ …, attachments: [{ filename, content: Buffer, contentType }] })` works on both transports
|
||||
(nodemailer's shape). Form files use it: a file a visitor attaches is e-mailed and never stored
|
||||
([forms.md](./forms.md) "Files"). Base64 adds 37 %: a 10 MB file is a 13.7 MB message.
|
||||
|
||||
### SMTP
|
||||
|
||||
The adapter passes attachments straight to nodemailer; the plugin sets no limit. The limit is the **mail server's**,
|
||||
and it counts the encoded message: a server limit of 10 MB carries about a 7 MB file, 25 MB about 18 MB, 35 MB
|
||||
about 25 MB. The recipient's mailbox has its own limit too. Do not trust a table — **measure**: Site integrations →
|
||||
E-mail sending → **Test e-mail** with **Attach a 10 MB test file** ticked (endpoint: `POST /api/ipal/test-email`,
|
||||
body `{ to, attachmentMB }`, 1–25). A server that refuses the size answers at send time (`552 …`); the adapter
|
||||
reports `{ sent: false, detail }`.
|
||||
|
||||
### Microsoft Graph
|
||||
|
||||
| Attachments in one message | How it is sent | Permission | Left in the mailbox |
|
||||
|---|---|---|---|
|
||||
| under 3,000,000 bytes in total | inside the one `sendMail` call | `Mail.Send` | nothing (`saveToSentItems: false`) |
|
||||
| more | a **draft** is created in the sender mailbox, files are added (an **upload session** for files of 3 MiB and more, in pieces of 3.2 MB), the draft is sent | `Mail.ReadWrite` | a copy passes through Drafts and Sent Items; **the plugin deletes it** |
|
||||
|
||||
The large path, step by step, and what happens when it fails:
|
||||
|
||||
- Any failure before the send (creating the draft, an upload, the send call) → the draft is deleted at once and the
|
||||
result is `{ sent: false, code: 'graph-error' }`. Nothing with the file stays in the mailbox.
|
||||
- After a successful send the copy in Sent Items is deleted: the plugin looks at the message after 2 s, 5 s, 15 s and
|
||||
60 s (`cleanupDelaysMs`), and deletes it once it has left Drafts — never earlier, so the send is not cancelled.
|
||||
It uses `permanentDelete`, and a plain delete when that is not available. If the copy could not be removed, the
|
||||
server log says `delete it by hand (it holds a form file)`.
|
||||
- The app's token lacks `Mail.ReadWrite` → nothing is created; the result is `code: 'graph-permission'` and the
|
||||
log names the permission. With `mailAdapter()`:
|
||||
- the panel has SMTP settings → the message goes **over SMTP** instead;
|
||||
- no SMTP settings → the send fails, and the form's file limit drops to about 2.8 MB so visitors are not offered
|
||||
more than can be sent; the panel shows "Microsoft Graph cannot send files of 3 MB and more here…".
|
||||
- **Turn it off:** `mailAdapter({ graph: { largeAttachments: false } })` (or `graphAdapter({ largeAttachments: false })`)
|
||||
— Graph keeps to small attachments; larger ones go over SMTP when the panel has SMTP settings, else the limit
|
||||
is about 2.8 MB.
|
||||
- `mailAttachmentLimit(payload)` (root) → the ceiling in bytes the current transport can carry, or `null`.
|
||||
|
||||
#### Azure / Exchange steps for large attachments (one-time, outside the code)
|
||||
|
||||
1. **Azure portal → App registrations → the app → API permissions → Add → Microsoft Graph → Application
|
||||
permissions → `Mail.ReadWrite` → Grant admin consent.** Keep `Mail.Send`. `Mail.Read` is not used by the
|
||||
plugin — remove it if nothing else needs it.
|
||||
2. **Limit the app to the forms mailbox.** Application permissions cover *every* mailbox of the tenant, and the
|
||||
app's secret sits in the environment of every project. In Exchange Online PowerShell:
|
||||
```powershell
|
||||
# a mail-enabled security group that holds only the sender mailbox
|
||||
New-DistributionGroup -Name "ipal-forms-mailbox" -Type Security -Members [email protected]
|
||||
New-ApplicationAccessPolicy -AppId <GRAPH_CLIENT_ID> -PolicyScopeGroupId ipal-forms-mailbox `
|
||||
-AccessRight RestrictAccess -Description "ipal-kit: only the forms mailbox"
|
||||
Test-ApplicationAccessPolicy -AppId <GRAPH_CLIENT_ID> -Identity forms@intecion.pl # AccessCheckResult: Granted
|
||||
Test-ApplicationAccessPolicy -AppId <GRAPH_CLIENT_ID> -Identity someone.else@intecion.pl # AccessCheckResult: Denied
|
||||
```
|
||||
A new policy can take up to an hour to apply. (Microsoft is moving this to "RBAC for Applications" in
|
||||
Exchange Online; a management scope limited to the same mailbox does the same job.)
|
||||
3. Nothing changes in the project: the same four `GRAPH_*` variables.
|
||||
|
||||
**Verify on the real tenant** (the plugin's tests run against a mocked Graph — no test touched a real mailbox):
|
||||
|
||||
- [ ] Test e-mail with the 10 MB file, transport = Microsoft Graph → arrives with the file intact.
|
||||
- [ ] After a minute, **Drafts and Sent Items of the sender mailbox do not contain the message** (also check
|
||||
Deleted Items and Recoverable Items — whether `permanentDelete` is honoured on your tenant).
|
||||
- [ ] `GRAPH_SENDER` is a **shared mailbox**: Microsoft lists a known issue with upload sessions on shared
|
||||
mailboxes. If the test fails with an access or "item not found" error, use `largeAttachments: false`
|
||||
(large files then go over SMTP) and report it.
|
||||
- [ ] With the access policy in place, the send still works, and `Test-ApplicationAccessPolicy` denies other mailboxes.
|
||||
- [ ] A file of 2.9–3.1 MB (both sides of the switch) arrives.
|
||||
- [ ] Server log after a send: no `delete it by hand`.
|
||||
|
||||
## Transport switch — mailAdapter
|
||||
|
||||
`mailAdapter()` is a dispatcher: one adapter wired in the config, it picks the transport
|
||||
@@ -211,8 +283,9 @@ secrets are missing in .env → log + fallback to SMTP (no silent failure).
|
||||
## Test send — button in the panel
|
||||
|
||||
The E-mail sending tab has a **Send test** button: enter an address, click, and a test
|
||||
mail goes out through the CURRENT transport (`payload.sendEmail`). It shows the result (✓/✗ with the error). Endpoint
|
||||
`POST /api/ipal/test-email`, body `{ to }` (`admin` role only — needs roles from the `access` option:
|
||||
mail goes out through the CURRENT transport (`payload.sendEmail`). It shows the result (✓/✗ with the error).
|
||||
Tick **Attach a 10 MB test file** to check that the mail server takes a file of that size ("Attachments" above). Endpoint
|
||||
`POST /api/ipal/test-email`, body `{ to, attachmentMB? }` (`admin` role only — needs roles from the `access` option:
|
||||
not logged in → 401, other role → 403, bad address → 400, failed send → 502).
|
||||
Save your changes before the test — the endpoint reads from the database, not from the field on screen.
|
||||
|
||||
@@ -246,6 +319,7 @@ send (e.g. **Send test**) the current one appears.
|
||||
- **Choosing the transport:** `mailAdapter()` (the panel decides) or a fixed `panelSmtpAdapter()` /
|
||||
`graphAdapter()`; any other Payload adapter (e.g. `@payloadcms/email-nodemailer`) also works —
|
||||
then you skip the panel SMTP and the send status.
|
||||
- **Override:** `fallbackFromAddress` / `fallbackFromName`, in `mailAdapter` separately `smtp` and `graph`.
|
||||
- **Override:** `fallbackFromAddress` / `fallbackFromName`, in `mailAdapter` separately `smtp` and `graph`
|
||||
(`graph.largeAttachments: false` keeps Graph to attachments under 3 MB — "Attachments").
|
||||
- **Extend:** form mail content is modified by `forms.beforeEmail` (see [forms.md](./forms.md));
|
||||
your own mail — `sendEmail` (SMTP) or `payload.sendEmail` (through the wired adapter).
|
||||
|
||||
Reference in New Issue
Block a user