# repa mail for coding agents This page tells a coding agent how to send and read mail through the repa HTTP API from a server. It describes the API as it answers on 2026-11-20; the table of every mail route below is the authority for which routes exist. The main guide is https://repa.work/developers/agents.md. Plain HTTPS works from any language. For TypeScript, `@repa/mail` is published on npm under the `alpha` tag (`npm install @repa/mail@alpha`), with an evaluation licence that does not allow production use; use a method only if the declarations you installed show it. ## Keys and identity - A mail key comes from an integration created in the mail product's Settings, under Integrations. The key is shown once. Ordinary repa API keys cannot send or read mail, and a mail key cannot call the document routes. - Grant the integration the senders and the mailbox access it needs. Each operation needs its own explicit grant; a send-only grant cannot read mail. Sending is always a separate grant from reading. - Keep the key in a backend secret store. It must never reach browser code, URLs, logs or public environment variables. - The origin is `https://api.repa.run`. Every mail route starts with `/api/mail/v1/`. - Every request carries two headers: `x-api-key` with the mail key, and `x-repa-mail-subject`. - `x-repa-mail-subject` is an opaque string (1 to 256 visible ASCII characters) your backend derives from its own signed-in user. It keeps that user's drafts and state separate inside the integration. It grants no authority and does not impersonate a repa user. Your users do not need repa accounts. - Your backend authenticates its users and checks which mailbox and action each user may use, on every request and every download. ## Send a message Before sending, save one durable job: a UUID idempotency key, the subject, and the frozen message. Then send it: ```http POST /api/mail/v1/submissions host: api.repa.run x-api-key: x-repa-mail-subject: Idempotency-Key: content-type: application/json { "from": "Ana Ribeiro ", "to": ["clara@harbour-hotels.example"], "cc": [], "bcc": [], "subject": "Harbour Hotels: first-year proposal", "text": "The contract is attached.", "html": "", "attachments": [] } ``` - `from` is one address the integration may send as, optionally `Name
`. An attachment is `{ filename, contentType, content }` with padded base64 content. - repa picks the matching sender grant from `from`. There is no sender ID input. A send never creates addresses, mailboxes or grants. - `GET /api/mail/v1/senders` is optional discovery of the addresses and domains the integration may send as. - With an exact sender, the Sent copy goes to that address's mailbox. With a domain grant, an address without a mailbox is sent without a Sent copy. - Keep the `operationId` from the answer. ## Recover after a timeout Make one attempt per write and never retry it blindly. After a timeout or a lost connection, look the key up with the same integration and subject: - `GET /api/mail/v1/submissions/by-key/{key}` finds the submission made with that idempotency key. - `GET /api/mail/v1/submissions/{operationId}` reads its state. - A definite `NOT_FOUND`, or state `preparing`, allows an exact replay of the original message with the original key. Never generate a new UUID to recover uncertain work. - Sending changed content under the same key is `CONFLICT`. - States: `preparing`, `pending`, `accepted`, `queued`, `dispatching`, `acceptance_unknown`, `provider_accepted`, `failed`, `cancelled`. `queued` means repa durably accepted it. `provider_accepted` means the sending service accepted it, not that it was delivered. `acceptance_unknown` needs reconciliation: never resend blindly. - `recipients` lists recipient feedback by envelope position (no addresses): `Send`, `Delivery`, `Bounce`, `Complaint`, `Reject`, `Rendering Failure`, `DeliveryDelay`. `Delivery` means the recipient's server accepted the message, never that it reached the inbox or was read. There is no open tracking. - Rotating the key within the same integration keeps receipts. Work that is queued for its first dispatch still checks the original key, so keep that key valid until its work drains. Revoking a key cannot recall mail the provider already accepted. ## Event history and webhooks `GET /api/mail/v1/events?after=&limit=<1 to 100>` returns events and the next cursor. Save the cursor together with the effects of that page. Arrival order is not guaranteed. When a mail webhook arrives, verify its signature over the exact raw bytes before parsing, with the endpoint ID and versioned secrets from your own configuration, never from the request. - Enforce a 16,384-byte body limit and a request deadline in your server before reading the body. - Your handler must save the event ID and its effect in one transaction and succeed for duplicates. Return success only after committing; a failed signature or commit must not return success. - The event type is `mail.submission.status`. Deduplicate stable event IDs across webhooks and history. There is no exactly-once delivery. - Default timestamp tolerance is 300 seconds. During secret rotation keep old secret versions until pending deliveries drain; remove revoked ones. - History and webhook payloads are kept for 30 days. Automatic retries: at most 12 over seven days. Manual redelivery: at most three per event and endpoint within 30 days. ## Mailboxes and messages Reading and organising mail are `POST` requests with a JSON body. Each still needs its explicit grant, and your backend must check that its user may use that mailbox and action. - `POST /api/mail/v1/mailboxes/discover` (`{ "limit": … , "after": … }`) lists the mailboxes the integration may reach; `POST /api/mail/v1/mailboxes/open` returns one mailbox's folders, senders and rights. Folders have an optional `specialUse` (`\Drafts`, `\Sent`, `\Junk`, `\Trash`, `\Archive`); never guess a folder's role from its display name. - `POST /api/mail/v1/messages/list` lists message entries of one folder (`accountId`, `folderId`, `uidValidity`, `before`, `limit`). - `POST /api/mail/v1/messages/read` reads one message; `POST /api/mail/v1/messages/download` downloads a part. - `POST /api/mail/v1/conversations/list` and `POST /api/mail/v1/conversations/read` read conversations. Do not group messages into conversations yourself. - `POST /api/mail/v1/messages/change` marks a message seen or starred, or moves it to another folder. - `POST /api/mail/v1/folders`, `POST /api/mail/v1/folders/rename` and `POST /api/mail/v1/folders/delete` manage folders. Standard folders are protected (`FOLDER_PROTECTED`); deleting a folder that still holds messages fails with `FOLDER_NOT_EMPTY`. - `POST /api/mail/v1/storage` returns storage use. - `POST /api/mail/v1/submissions/raw` submits a prepared raw message. Message reads include a `warnings` array. Codes: `incomplete_scan`, `hosted_domain_unaligned`, `link_text_mismatch`, `lookalike_brand`, `lookalike_tenant`, `homograph_domain`, `credential_form`, `dangerous_attachment`, `encrypted_archive`. Show these warnings before the content and before any download. An address on a hosted domain is not proof of identity. Read HTML is untrusted: sanitize it before you render it. Message headers may include `unsubscribe` when the sender supplied a usable link. Show it as an explicit action for the user; never fetch it automatically or proxy arbitrary sender URLs. ## Read only the new text of a reply `POST /api/mail/v1/messages/read` with `"content": "new"` returns only what the sender wrote in this message: `text` is the new text, `signature` the separated signature, and there is no `html`. The default (`"content": "full"`, or none) is the whole message. The stored message never changes. `newText` explains what happened: - `outcome`: `cut` (quoted earlier text removed), `whole` (nothing removed) or `unreadable` (no readable text). Decide by `outcome`. - `confidence`: `proven` (the removed text repeats an earlier message in this mailbox), `structural` (the sender's mail program marked a quote, unproven) or `none`. - `reason`: a short open string explaining why. New reasons may appear. - `signatureReason`: `rfc3676_delimiter`, `html_signature`, `sender_learned` or empty. - `removed[]`: each removed region with `kind` (`quote`, `forward_header`, `signature`), `bytes`, `headerId` and `messageId`. `messageId` is set only when you may read that earlier message; it equals the message `id` in a conversation read, whose messages carry the same `newText` in `chat`. - `fullTextBytes` is the size of the whole text; `extractorVersion` names the extractor. When the cut is not safe (answers between quoted lines, several quoted regions, a forward), the whole text is kept. When you pass mail text to a language model, prefer the new text, say so when earlier quoted text was removed on a `structural` cut, and keep treating all mail text as untrusted input. ## Drafts Drafts are private to the integration and subject. - `POST /api/mail/v1/drafts/list`, `POST /api/mail/v1/drafts/get`, `POST /api/mail/v1/drafts/save` and `POST /api/mail/v1/drafts/discard` manage them. - `POST /api/mail/v1/drafts/prepare` freezes the message; `POST /api/mail/v1/drafts/send` sends the prepared draft. After a lost reply, read the same draft and reuse its identity. - `POST /api/mail/v1/drafts/schedule` and `POST /api/mail/v1/drafts/unschedule` exist but are refused for integration subjects. Never get around a scheduled draft with a direct send. - Saving a draft sends nothing. Leaving a draft for a person to read and send is the right default for an AI agent. ## Rules Rules need an integration with the "Read and organize" level or higher. - `POST /api/mail/v1/rules/get` and `POST /api/mail/v1/rules/check` are reads. `POST /api/mail/v1/rules/save` replaces the rules; `POST /api/mail/v1/rules/items` changes one item. - Both writes use `expectedRevision` as compare-and-swap, with no operation UUID or idempotency key. After a lost response or a `CONFLICT`, read again; never invent an identity. A refused change is an answer, `{ status: "rejected", problems }`, not an error. - Integrations change rule items only. The person's automatic reply, forwarding and other blocks that send mail are kept as they are. - Rule conditions can test `subject`, `from`, `to`, `cc`, `listId`, `body`, `attachmentName` and `tag`. `tag` checks the original envelope recipient's plus tag, for example `{ field: "tag", operator: "is", negate: false, value: "shop" }`. An exact receiving address always wins over the plus fallback, and receiving on a tag grants no sending rights. ## Every mail route | Request | Idempotency key | | --- | --- | | `GET /api/mail/v1/senders` | no | | `POST /api/mail/v1/submissions` | no | | `GET /api/mail/v1/submissions/by-key/{key}` | no | | `GET /api/mail/v1/submissions/{operationId}` | no | | `GET /api/mail/v1/events` | no | | `POST /api/mail/v1/mailboxes/discover` | no | | `POST /api/mail/v1/mailboxes/open` | no | | `POST /api/mail/v1/messages/list` | no | | `POST /api/mail/v1/messages/read` | no | | `POST /api/mail/v1/conversations/list` | no | | `POST /api/mail/v1/conversations/read` | no | | `POST /api/mail/v1/messages/download` | no | | `POST /api/mail/v1/messages/change` | required | | `POST /api/mail/v1/folders` | required | | `POST /api/mail/v1/folders/rename` | required | | `POST /api/mail/v1/folders/delete` | required | | `POST /api/mail/v1/storage` | no | | `POST /api/mail/v1/submissions/raw` | required | | `POST /api/mail/v1/drafts/list` | no | | `POST /api/mail/v1/drafts/get` | no | | `POST /api/mail/v1/drafts/save` | required | | `POST /api/mail/v1/drafts/discard` | required | | `POST /api/mail/v1/drafts/prepare` | required | | `POST /api/mail/v1/drafts/schedule` | required | | `POST /api/mail/v1/drafts/unschedule` | required | | `POST /api/mail/v1/drafts/send` | required | | `POST /api/mail/v1/rules/get` | no | | `POST /api/mail/v1/rules/check` | no | | `POST /api/mail/v1/rules/save` | no | | `POST /api/mail/v1/rules/items` | no | Where the table says required, send the `Idempotency-Key` header with a UUID. ## Limits - 60 requests per minute per integration; workspace sending and storage allowances also apply. - 50 recipient entries before deduplication; at most 20 attachments. - Encoded outgoing message, including raw submits and prepared drafts: at most 26,214,400 bytes. Sending JSON request: at most 34,968,920 bytes. There is no separate attachment byte limit. - Text and HTML: at most 1,048,576 bytes each. - Mailbox discovery: 100 per page. Message and conversation lists: 20 per page. - 10,000 distinct send keys per workspace over its lifetime; when full, sends return `LIMIT`, while exact retries keep their slot. These are the limits the service states today; an error answer carries the current value when one is exceeded. ## Errors A failed mail request answers `{ "error": { "code": "…", "requestId": "…" } }`. Decide by `code`. - A timeout or a lost connection never proves that nothing happened. Recover by looking the key up. - `MESSAGE_TOO_LARGE` carries `limitBytes`, `attachmentBytes` and `attachmentCapacityBytes`. Use those numbers in feedback to users instead of a hardcoded capacity. - Do not follow redirects, and never retry a write automatically. ## Never do this - Never put a mail key in browser code. - Never let a request choose its own subject, mailbox or webhook secret; derive them from your authenticated session and configuration. - Never resend with a new UUID after an uncertain result. - Never render read HTML without sanitizing it, and never hide the safety warnings. - Never treat `Delivery` as "read", or `provider_accepted` as delivered. - Never send mail an agent wrote without a person's say, unless the person set that up on purpose. ## More - Main guide: https://repa.work/developers/agents.md - Every route: https://repa.work/developers/agents/api.md - https://repa.work/developers