Quellcode durchsuchen

docs: the SMTP port block, the per-call account, no idempotency key, no inline images

NOT IN THE PUBLISHED 0.13.0; ships with curl tomorrow.

Four things about ctx.mail that were in our internal notes and not in the
published docs. A consumer asked all four from first principles today because
there was nowhere to read them, which is the silence-propagates failure again
- their stale note came from a message of mine that said "WILL build a
ctx.mail", and nothing in llms.txt corrected it.

The expensive one: on a DigitalOcean droplet outbound 25, 465 and 587 are
blocked by the provider and only 2525 is open. A send on a blocked port is
mail_timeout 504 with retryable false, which is the right answer and reads
exactly like a bad credential or a dead server - the hardest failure here to
diagnose from the error alone. They were about to build a daily report on it.

The one that answered their actual question: the sending ACCOUNT is per call,
with no project-level mailbox and no default. That matters when the mailbox
and the data have different owners - they had sent internal commercial
figures through a mailbox inside their customer's tenant, where the
customer's administrator could read them in Sent. The remedy is just to pass
your own connection fields, and it is worth documenting as a capability
rather than leaving someone to discover it.

Also: no idempotency key on send, deliberately, because a send is never
retryable once delivery was possible so there is nothing to deduplicate
against - with the sent-marker pattern named, since a daily report wants
at-most-once and has to build it itself. And inline cid images are not
expressible: attachments carry no content-id and the structure is never
multipart/related, so a cid: reference has nothing to resolve against.

My earlier message had also promised an idempotency key that never shipped,
so that note was wrong twice. A capability claim in a message needs a date
and a re-check; one in the docs needs to exist.
fszontagh vor 1 Monat
Ursprung
Commit
a9d0c5204b
1 geänderte Dateien mit 4 neuen und 0 gelöschten Zeilen
  1. 4 0
      api/llms.txt

+ 4 - 0
api/llms.txt

@@ -287,6 +287,10 @@ export default async function (ctx) {
   - **`criteria` is a structured object, never raw IMAP syntax** - the only string accepted is `'ALL'` (the default). Fields: `since`, `before`, `from`, `to`, `subject`, `text`, `body`, `headerName`+`headerValue`, `unseen`, `seen`, `flagged`, `largerThanBytes`, `smallerThanBytes`. `headerName` and `headerValue` are one criterion in two halves and must both be given, because a server answers a half-stated one with a syntax error rather than with a match. **A non-ASCII criterion value is REFUSED** (naming the field): expressing it needs a multi-step `CHARSET UTF-8` literal exchange this transport does not drive, and sending the bytes anyway makes the server match nothing - and zero results is indistinguishable from "there is no such mail", which is a silently wrong answer rather than a missing feature. Filter on an ASCII-safe criterion, or on sender or date, and match accented text yourself after fetching. Mailbox NAMES are unaffected and may be non-ASCII.
   - `ctx.mail.mailboxes({...})` -> `[{name, nameEncoding, flags, delimiter}]`. Names are decoded from IMAP's modified UTF-7, so `Beérkezett` arrives readable.
   - `ctx.mail.send({from, to, cc, bcc, subject, text, html, attachments, replyTo, headers, inReplyTo, references, ...})` -> `{ok: true, accepted: [...]}`. `to`/`cc`/`bcc` take a string or an array. Structure is chosen for you: text only is `text/plain`, text plus `html` is `multipart/alternative`, and attachments wrap it in `multipart/mixed`. Attachments are `{filename, contentType, base64}`. **`bcc` recipients receive the message but appear in no header of it.** A non-ASCII subject, display name or filename is encoded correctly (RFC 2047, and RFC 2231 for filenames). An address, subject, filename or header containing CR or LF is **refused by name** - that is header injection.
+  - **CHECK WHICH SMTP PORT YOUR HOST ALLOWS BEFORE WRITING THE FUNCTION. On a DigitalOcean droplet, outbound 25, 465 and 587 are BLOCKED by the provider and 2525 is open.** Measured on ours, and confirmed as the host's policy rather than any mail server's by `smtp.gmail.com:587` and `smtp.sendgrid.net:587` being blocked identically. A send on a blocked port fails as `mail_timeout` **504** after about 7 seconds with `retryable: false` - which is the correct answer and reads exactly like a wrong credential or a dead server, so it is the hardest failure here to diagnose from the error alone. A send over **2525 with STARTTLS works**, verified end to end through the deployed runner (accepted in ~1.3 s, then found by `UID SEARCH` and fetched back). IMAP 993 and 143 are unaffected and open. So **confirm your provider offers 2525** before building, and remember this is a property of the HOST your runner sits on rather than of this API.
+  - **The sending ACCOUNT is per call, and there is no project-level mailbox or default account.** `host`, `port`, `user`/`userSecret` and `password`/`passwordSecret` are options on every one of the three calls. That is deliberate and it matters when the mailbox and the data have different owners: a function running for a customer's project can send from YOUR OWN identity without the customer's mail system being involved at all, and nothing about the project binds the sender. A consumer sent internal commercial figures through a mailbox living inside their customer's tenant, where the customer's administrator could read them in the Sent folder; the remedy is simply to pass your own connection fields.
+  - **There is NO idempotency key on `send`, deliberately.** A send is never reported as retryable once the conversation could have reached delivery, because a duplicate e-mail cannot be recalled - so there is nothing for a key to deduplicate against. If you need at-most-once for something like a daily report, the guard is yours: write a sent-marker row before the send and check it on the next tick.
+  - **Inline images are NOT expressible.** Attachments are `{filename, contentType, base64|text}` with no content-id, and the structure is chosen for you - `text/plain`, `multipart/alternative` with `html`, wrapped in `multipart/mixed` when there are attachments. There is no `multipart/related`, so a `cid:` reference in your HTML has nothing to resolve against. Use an `https` image (most clients block remote images until the recipient allows them), attach the file normally, or leave it out; a `data:` URI is stripped by several clients including Outlook.
   - **Mail hosts go through the same SSRF guard as `ctx.fetch`**, so loopback, private and link-local destinations are refused (`egress_blocked`, with the guard's reason) and a function cannot reach a mail server on the API host. The name is resolved **once** and every address it returns is classified, then the approved address is pinned for the connection - re-resolving is the rebinding window. Plaintext (`tls:false, startTls:false`) to anything but a loopback literal is refused as `mail_tls_required`.
   - **One run may load at most 4 MiB of mail**, independently of any mailbox size, because a run holds a pooled runtime with its own memory limit. Exceeding it is **422** `mail_too_large` - deliberately not a timeout, because the remedies differ and a caller told "timeout" for an oversized mailbox retries forever.
   - **Slugs worth branching on**, each with `details.retryable`: `mail_timeout` **504**, `mail_too_large` **422**, `mail_incomplete` (the server stopped mid-message; retryable, since a peek fetch changed nothing), `mail_rejected` **422** (the server refused permanently, usually a bad recipient or sender - its reply text is included), `mail_server_busy` **503** (a transient 4xx; retryable), `mail_auth_failed` (**never** retryable - repeating a rejected login is how an account gets locked), `mail_tls_untrusted` (the certificate did not verify; never retried and never downgraded), `mail_unreachable` and `mail_unresolvable` (retryable, nothing reached the server). **A send is never reported as retryable** once the conversation could have reached delivery, because a duplicate e-mail cannot be recalled.