Using the JMAP API
ServerlessInbox implements JMAP (RFC 8620) and JMAP for Mail (RFC 8621). All JMAP traffic goes through a single HTTP endpoint.
Endpoint URL
Section titled “Endpoint URL”The JMAP API is served at jmap.<your mail domain>. The ACM certificate and Route 53 record are created for you during deployment. The exact URL for your deployment is published as the jmapApiUrl output — open your stack’s Outputs tab in the CloudFormation console to read it.
Your mail domain is derived from the Route 53 hosted zone you selected when you launched the stack. If you set the optional subdomainNamespace parameter, that label is inserted between the service name and the base domain:
Hosted zone / subdomainNamespace | JMAP endpoint |
|---|---|
example.com, namespace left empty | https://jmap.example.com |
example.com, namespace mailbox | https://jmap.mailbox.example.com |
Authentication
Section titled “Authentication”The JMAP API requires a Bearer JWT issued by the deployment’s identity provider — a Cognito user pool unless a different IdP addon is configured. The token must carry the jmapApi audience.
A request without valid credentials is answered 401 Unauthorized with a WWW-Authenticate: Bearer header. When the deployment is configured for OAuth, the challenge also carries a resource_metadata parameter pointing at the OAuth protected-resource document, so a client can discover the authorization server from the 401 alone.
Mail scopes
Section titled “Mail scopes”These are the scope strings a client requests and an operator selects in the identity-provider
console. They are produced by the identity-provider construct from a resource server whose
identifier is si, so every mail scope is the identifier, a slash, and a dotted scope name.
Transcribe them exactly as written:
| Scope string | Grants |
|---|---|
si/mail.read | Read operations |
si/mail.write | Mutations |
si/mail.send | Sending |
These three are the mail scopes; the same resource server also publishes si/account.read,
si/alias.read, si/alias.write, si/user.read, si/contacts.read, si/contacts.write,
si/admin and si/tokens.manage.
si/tokens.manage carries one permission, tokens/manage, which lets a client create, rotate and revoke the
signed-in user’s personal access tokens. No other scope carries it, and
si/user.read does not. A client is given it by being provisioned with Permission.TOKENS_MANAGE; the webmail
client requests it. Tokens a client creates are limited to anything up to the user’s own rights, and a personal
access token can never hold tokens/manage, so a token cannot create or renew tokens.
CDK consumers do not write these strings by hand — they pass Permission.MAIL_READ,
Permission.MAIL_WRITE and Permission.MAIL_SEND to the construct, which maps each one to the
scope string above. Permission.MAIL_READ is a construct API name, not a scope string; never put
it in a token request.
Scope enforcement: A method call is admitted only when the token’s scopes allow at least one of the rights the method works with (see Rights and token limits). Otherwise the call fails with a method-level forbidden error, and no data is read or written. A token that passes this check is then limited further, object by object, by what the signed-in user may do.
Rights and token limits
Section titled “Rights and token limits”A token never grants anything; it only limits. What a request may do is what the signed-in user may do, intersected with what the token allows. A token that allows writing grants nothing on a mailbox the user can only read, and the owner of an account who presents a read-only token cannot write to it.
A token limit is a set of rights. Rights are namespaced names; the scopes in Mail scopes expand to them.
| Right | Allows |
|---|---|
mail/readItems | Read mailboxes, emails, threads and submissions |
mail/addItems | Add an email to a mailbox: create, import, copy, move in; upload and Blob/copy into the account |
mail/removeItems | Remove an email from a mailbox, or destroy it |
mail/setSeen | Change the $seen keyword |
mail/setKeywords | Change keywords other than $seen |
mail/createChild | Create a mailbox under a mailbox; create a top-level mailbox |
mail/rename | Rename, reorder or move a mailbox |
mail/delete | Destroy a mailbox |
mail/submit | Send mail and manage identities |
contacts/read | Read address books, contact cards and principals |
contacts/write | Create and change address books and contact cards, and share address books |
contacts/delete | Destroy address books |
preferences/read, preferences/write, import/read, import/write, admin | Further rights a token limit can name |
tokens/manage | Create, rotate and revoke personal access tokens |
What the session and objects show
Section titled “What the session and objects show”The limit is visible to a client, so it can disable what would be refused:
isReadOnlyon an account in the session istruewhen the user and token together allow no write of any kind on it.accountCapabilitiesleaves out a capability when the user and token together allow nothing of that kind on the account. An account with nothing at all allowed is omitted from the session.myRightson aMailboxand on anAddressBookreflects the limit: a right the token does not allow isfalse, even for the account owner.
Which right a write needs
Section titled “Which right a write needs”| Operation | Needs |
|---|---|
Email/set create, Email/import, Email/copy | mail/addItems on each target mailbox |
Email/set update, any change | mail/readItems on a mailbox the email is in, then the right named in the rows for that change |
Email/set update, mailbox added | mail/addItems on that mailbox |
Email/set update, mailbox removed | mail/removeItems on that mailbox |
Email/set update of $seen | mail/setSeen on every mailbox the email is in |
Email/set update of any other keyword | mail/setKeywords on every mailbox the email is in |
Email/set destroy | mail/readItems on a mailbox the email is in, and mail/removeItems on every mailbox the email is in |
EmailSubmission/set create | mail/readItems on a mailbox the email is in, and mail/submit on every mailbox the email is in |
EmailSubmission/set update, destroy | mail/submit |
EmailSubmission/set onSuccessUpdateEmail, onSuccessDestroyEmail | The same rights as the equivalent Email/set change; when refused, the email stays unchanged |
Blob/copy | mail/addItems on the destination account |
Identity/set | mail/submit |
Mailbox/set create a top-level mailbox | Account owner, and mail/createChild |
Mailbox/set create a child mailbox | mail/createChild on the parent |
Mailbox/set rename, change sortOrder | mail/rename |
Mailbox/set move under another mailbox | mail/rename, and mail/createChild on the new parent |
Mailbox/set move to the top level | mail/rename, and account owner |
Mailbox/set destroy | mail/delete; with onDestroyRemoveEmails, also mail/readItems and mail/removeItems on that mailbox. An email also in another mailbox only leaves this one |
Mailbox/set change shareWith | mail/rename and mail/delete; a share may not give more than the sharer’s token allows |
AddressBook/set create | Account owner (a user), and contacts/write |
AddressBook/set update name, description, isDefault, sortOrder | contacts/write |
AddressBook/set change shareWith | contacts/write with share permission on the book |
AddressBook/set destroy | contacts/delete |
ContactCard/set create, update, destroy | contacts/write on the address book, and on the target book when a card is moved |
A token that sends mail also needs mail/readItems, because sending reads the message. The token editor in webmail turns on reading for rights that act on a message.
A mailbox, email or address book the user or token cannot read is reported as notFound rather than forbidden.
Subscribing to a mailbox (isSubscribed) needs no right and gives none.
Errors
Section titled “Errors”| Situation | Error |
|---|---|
| The user has no right of any kind on the account | accountNotFound |
| The method works with a kind of data (mail or contacts) that the user and token allow nothing of on the account | accountNotSupportedByMethod |
| A read method, and the user and token allow no read of this kind | forbidden for the method |
A write method, and the account is read-only (isReadOnly is true) | accountReadOnly |
| A write method on an account that is not read-only, but no write of this kind is allowed | forbidden for the method |
/copy source account: no right of any kind | fromAccountNotFound |
/copy source account: nothing of this kind allowed | fromAccountNotSupportedByMethod |
/copy source account: no read of this kind allowed | forbidden for the method |
| The token’s scopes do not allow the method | forbidden for the method |
| A write on one object needs a right that is not held | forbidden on that item in notCreated, notUpdated, notDestroyed or notCopied; the rest of the call proceeds |
EmailSubmission/set create with an email that cannot be read | invalidProperties on that item |
| A mailbox, email or address book the user or token cannot read | notFound |
Machine-to-machine (headless) access
Section titled “Machine-to-machine (headless) access”Provisioning the client (CDK deployments)
Section titled “Provisioning the client (CDK deployments)”Machine-to-machine access requires a deployment built with the ServerlessInbox CDK constructs. A headless app client is not part of a template install — it exists only where the CDK app asks for one explicitly, by calling provisionHeadlessClient({ name, audiences, permissions }) on the MailServerUserPool construct. That call creates a dedicated client_credentials app client and registers it as an accepted audience on the APIs listed in audiences; it returns the client’s ID, its generated client secret as a SecretValue, and the scope strings the client may request.
Where those values go is the deployment’s own choice — the constructs do not store them anywhere. The recommended handling is for the CDK app to put the secret straight into AWS Secrets Manager and never surface it any other way:
const client = userPool.provisionHeadlessClient({ name: 'sync-worker', audiences: ['jmapApi'], // Construct API names, not scope strings: these map to `si/mail.read` and `si/mail.write`. permissions: [Permission.MAIL_READ, Permission.MAIL_WRITE],});
// clientSecret is set for headless (client_credentials) clients.new secretsmanager.Secret(this, 'SyncWorkerClientSecret', { secretName: 'serverlessinbox/headless/sync-worker', secretStringValue: client.clientSecret!,});Do not publish the secret as a CfnOutput and do not pass it into a construct property that lands verbatim in the synthesized template: a stack output and a plaintext template value are both readable by anyone with read access to the stack.
The client ID is not a secret and may be published as a stack output or hard-coded in the consumer’s configuration.
Using the client (any consumer)
Section titled “Using the client (any consumer)”The flow itself is standard OAuth 2.0 client_credentials. The client must carry the jmapApi audience and the mail scopes the integration needs: si/mail.read for reads, plus si/mail.write and si/mail.send for mutations and sends — see Mail scopes above.
Read the secret at run time from Secrets Manager rather than pasting it into the command, and authenticate to the token endpoint with HTTP Basic auth (client_secret_basic) so the secret is never in the POST body:
# 1 — Fetch the client secret at run time; never paste it into the command.CLIENT_ID=<headless-client-id>CLIENT_SECRET=$(aws secretsmanager get-secret-value \ --secret-id serverlessinbox/headless/sync-worker \ --query SecretString --output text)
# 2 — Obtain a token. --user sends Basic auth, keeping the secret out of the body.# The token endpoint comes from the openid-configuration document; the Cognito form is shown here.TOKEN=$(curl -s -X POST \ --user "$CLIENT_ID:$CLIENT_SECRET" \ "https://<cognito-domain>.auth.<region>.amazoncognito.com/oauth2/token" \ -H "Content-Type: application/x-www-form-urlencoded" \ -d "grant_type=client_credentials" \ -d "scope=si/mail.read si/mail.write si/mail.send" \ | jq -r '.access_token')unset CLIENT_SECRETNever echo, log, or set -x over the secret or the token. Note that a process’s arguments are visible to other users on the host, so --user still exposes the secret on a shared machine — pass it on stdin with curl --config - there, or use an SDK that keeps it in memory.
The access token is short-lived (the identity provider returns its lifetime in expires_in). Cache it in memory and reuse it until it is close to expiry rather than requesting a new token per call.
Session discovery
Section titled “Session discovery”Before making method calls, fetch the JMAP session object. It describes the capabilities the server supports, the accounts the authenticated user has access to, and the API URL to use for calls.
curl -s "https://jmap.mail.example.com/.well-known/jmap" \ -H "Authorization: Bearer $TOKEN" | jq .The response includes an apiUrl (the endpoint for method calls) and the primaryAccounts map — you need the account ID for almost every method call.
Use the URLs the session gives you — do not assume a layout. This is the most common reason a JMAP client fails against a server it has not been tested with:
- Method calls go to
apiUrl, not to the session endpoint you just fetched. uploadUrlanddownloadUrlare RFC 6570 URI templates. Expand the variables —{accountId},{blobId},{type},{name}— rather than treating the string as a literal URL. Blob upload and download will not work otherwise.- The host may differ per URL: downloads are served from a CDN host in this deployment, which is exactly the case a hard-coded path gets wrong.
Principals in the session
Section titled “Principals in the session”The session lists urn:ietf:params:jmap:principals among its top-level capabilities as an empty object, as RFC 9670 defines. Each account’s accountCapabilities carries the same capability with a currentUserPrincipalId member: the id of the signed-in user’s own Principal. Fetch it with Principal/get to read that principal.
Upload size limit
Section titled “Upload size limit”A single upload to uploadUrl is capped at 6 MB — the request passes through API Gateway, and
that’s its payload ceiling. JMAP defines a single upload endpoint rather than per-object pre-signed
URLs, so this limit applies to the whole request body, attachments included; a message (or
attachment) that exceeds it is rejected at the gateway before it reaches the server. A JMAP
extension for presigned S3 uploads, which would lift this ceiling, is planned. ServerlessInbox
imposes no size limit of its own on receiving mail.
{ "capabilities": { "urn:ietf:params:jmap:core": { "maxCallsInRequest": 32, "..." : "..." }, "urn:ietf:params:jmap:mail": { "mayCreateTopLevelMailbox": true, "...": "..." }, "https://specs.serverlessinbox.com/websocket": { "url": "wss://ws.mail.example.com", "maxSubscriptions": 10 } }, "accounts": { "acc-abc123": { "name": "alice@example.com", "isPersonal": true, "isReadOnly": false, "accountCapabilities": { "urn:ietf:params:jmap:core": {}, "urn:ietf:params:jmap:mail": {}, "urn:ietf:params:jmap:submission": {} } } }, "primaryAccounts": { "urn:ietf:params:jmap:core": "acc-abc123", "urn:ietf:params:jmap:mail": "acc-abc123", "urn:ietf:params:jmap:submission": "acc-abc123" }, "apiUrl": "https://jmap.mail.example.com/jmap", "uploadUrl": "https://jmap.mail.example.com/upload/{accountId}", "downloadUrl": "https://cdn.mail.example.com?accountId={accountId}&blobId={blobId}&type={type}&name={name}"}Method coverage
Section titled “Method coverage”The table below is the complete, current picture of what the endpoint accepts. Every method the server implements is declared in the schemas served at the endpoint, and vice versa — there are no undeclared, implemented-but-hidden methods.
| Object | Methods | Notes |
|---|---|---|
Mailbox | get, set, query, queryChanges, changes | |
Email | get, set, query, queryChanges, changes, copy, import, parse | |
Blob | copy | RFC 8620 §6.3 (core). Copies email blobs between accounts — see Blob/copy below. |
Thread | get, query, queryChanges, changes | |
SearchSnippet | get | RFC 8621 §5.1. Highlights the words of an Email/query text filter — see Search below. |
EmailSubmission | get, set, query, queryChanges, changes | query/queryChanges are optional under RFC 8621 §7.4; implemented here. |
Identity | get, set, changes | set has a deliberately narrow contract — see Identity/set below. |
AddressBook | get, set, query, queryChanges, changes | RFC 9610 (Contacts). |
ContactCard | get, set, query, queryChanges, changes, copy | RFC 9610 (Contacts). |
Principal | get, set, query, queryChanges, changes | RFC 9670 (Principals/sharing). |
ShareNotification | get, set, query, queryChanges, changes | RFC 9670 (Principals/sharing). |
Core/echo | Not available | Deliberately not enabled: an unauthenticated echo endpoint is attack surface with no value to a real client. Use any cheap */get call (e.g. Mailbox/get with ids: []) to verify a token/connection instead. |
PushSubscription | get, set | Account-less webhook push, RFC 8620 §7.2 — see the PushSubscription reference. Requires the push/manage right. |
These methods back the urn:ietf:params:jmap:core, urn:ietf:params:jmap:mail, urn:ietf:params:jmap:submission, urn:ietf:params:jmap:contacts, and urn:ietf:params:jmap:principals capabilities the session advertises.
Calling a method the server does not implement returns a JMAP unknownMethod error, not silent success.
Identity/set
Section titled “Identity/set”Identities are provisioned by the server from an account’s aliases — which addresses an account may send from is a property of that account’s aliases (the Admin API’s can_send_from flag) — so Identity/set is a preferences editor, not a provisioning API:
createis always rejected withforbidden(“Identities are server-managed”).destroyis rejected for the account’s primary identity, which the server marksmayDelete: false.- On
update, a non-admin caller may setreplyTo,bcc,textSignature, andhtmlSignature;nameis rejected withinvalidPropertiesas server-managed.
A client that uses Identity/set for signatures and per-identity reply/BCC preferences works exactly as expected. One that tries to add a sending address through it gets a clean forbidden back and should send the user to the administrator instead.
Blob/copy
Section titled “Blob/copy”Blob/copy copies email blobs between accounts — the caller must be able to read the source blob in the source account and hold write rights on the destination account. It is part of the RFC 8620 core capability (urn:ietf:params:jmap:core), not the mail capability: unlike Email/copy, it is available regardless of which account capabilities are in play, and does not require urn:ietf:params:jmap:mail.
Its contract is email blobs. A request that names a contact or principal blob is refused for that item with invalidArguments, reported per item in the response’s notCopied map — the rest of the call proceeds normally, so one out-of-contract item never fails the whole request.
Search
Section titled “Search”Email/query and SearchSnippet/get take the same filter. This section describes how the text members of that filter behave and which members the server refuses.
Search text
Section titled “Search text”The text of text, subject, from, to, cc, bcc and body is read as words:
- A search of several words finds the mail that contains all of them.
- A phrase in single or double quotes finds the words together and in order. Inside a phrase, a backslash stands for the character after it, so
\"and\'put a quote in the phrase. - Everything typed is text. There are no operators:
OR,-,field:and*have no special meaning. To combine conditions, use the filter operatorsAND,ORandNOT. - A word matches whole words only, ignoring case. Stemming is not used, so
invoicedoes not findinvoices. - A value that holds only white space constrains nothing and matches every email.
What text and body cover
Section titled “What text and body cover”textcoversFrom,To,Cc,Bcc,Subjectand the body.bodycovers the body alone.- The body is the first 64 KiB of the readable text of the mail: the text part, or the HTML part reduced to its text when there is no text part, followed by text attachments and attached messages.
- For mail stored before its text was kept for search, the body is the 200-character preview.
This differs from RFC 8621 section 4.4.1 in that text and body read at most the first 64 KiB of the text of a mail.
text does not match keywords. To find mail by keyword, use hasKeyword or notKeyword.
Filter members
Section titled “Filter members”| Member | Matches |
|---|---|
before | Mail received before the date (exclusive). |
after | Mail received at or after the date. |
minSize | Mail of at least this many octets. |
maxSize | Mail of fewer than this many octets. |
hasAttachment | true finds mail with an attachment, false mail without. |
bcc | Mail whose Bcc header contains the words. |
body | Mail whose body contains the words, as described above. |
before and after are UTC dates ending in Z, such as 2025-03-01T00:00:00Z; minSize and maxSize are unsigned integers.
Refused members
Section titled “Refused members”A filter that carries one of these members gets an unsupportedFilter error (RFC 8620 section 5.5), as does any member that RFC 8621 does not define:
headerallInThreadHaveKeywordsomeInThreadHaveKeywordnoneInThreadHaveKeyword
A search the server cannot understand also gets unsupportedFilter. While the search index of an account is being built or upgraded, a search gets serverUnavailable; try again later.
SearchSnippet/get
Section titled “SearchSnippet/get”SearchSnippet/get returns, for each requested email, the subject and a preview with the words of the filter’s text marked. Its arguments and response are listed in the SearchSnippet reference; the behaviour is:
filteris the filter of theEmail/querycall. Only its positive text counts: words under aNOTare not marked.emailIdsholds at most 500 ids, themaxObjectsInGetof the session. More answersrequestTooLarge. An id given twice is answered once.- An id that is malformed, unknown, destroyed or in a mailbox the caller cannot read is listed in
notFound.notFoundisnullwhen every id was found. - Each found email is an item of
listwithemailId,subjectandpreview. The response has nostate. subjectis the whole subject, never cut.previewis cut to at most 255 octets.- In both, the marked words are wrapped in
<mark>and</mark>, and&,<and>are escaped as&,<and>. subjectisnullwhen no word of atextorsubjectcondition occurs in the subject.previewisnullwhen no word of atextorbodycondition occurs in the preview text. Asubjectcondition never marks the preview, and abodycondition never marks the subject.- A call with no
filter, or with no text condition, finds the emails and answersnullfor both.
Request format
Section titled “Request format”All JMAP method calls are sent as a single POST to the apiUrl:
POST /jmapAuthorization: Bearer <token>Content-Type: application/json
{ "using": ["urn:ietf:params:jmap:core", "urn:ietf:params:jmap:mail"], "methodCalls": [ ["<MethodName>", { ...arguments... }, "<clientId>"] ]}Each element of methodCalls is a 3-tuple:
- Method name — e.g.
Email/query,Mailbox/get - Arguments — the method’s argument object
- Client ID — an arbitrary string you choose (e.g.
"r1") to identify this call when referencing its result
The response is:
{ "methodResponses": [ ["<MethodName>", { ...response... }, "<clientId>"] ]}Errors
Section titled “Errors”A method that fails answers with an error response in place of its normal response, at the same position in methodResponses and with the same client ID. The other method calls in the request are processed as normal, and a method-level error never changes the HTTP status (RFC 8620 section 3.6.2).
["error", { "type": "invalidArguments", "description": "..." }, "<callId>"]type is always present. description is optional and meant for debugging, not for display to a user; do not match on its wording.
Method-level error types
Section titled “Method-level error types”type | Meaning |
|---|---|
unknownMethod | The server does not implement the method name. |
invalidArguments | An argument is of the wrong type, is otherwise invalid, or is missing; or a result reference in the call does not resolve. |
forbidden | The method and arguments are valid, but the request’s capabilities or token scopes do not allow the method, or the signed-in user may not run it. See Rights and token limits. |
accountNotFound | The accountId is not an account the user has any right on. |
accountNotSupportedByMethod | The account exists, but the user and token allow nothing of the kind the method works with (mail or contacts). |
accountReadOnly | The method writes, and the account is read-only. |
fromAccountNotFound | A /copy method’s fromAccountId is not an account the user has any right on. |
fromAccountNotSupportedByMethod | A /copy method’s source account allows nothing of the kind the method works with. |
cannotCalculateChanges | A */changes or */queryChanges call cannot be answered from the sinceState or sinceQueryState given. Fetch the data again and continue from the new state. |
tooManyChanges | A */changes call has more changes than the maxChanges the client asked for. Repeat the call with a larger maxChanges. |
requestTooLarge | A */set call names more objects to create, update or destroy than the server accepts in one call. Split the call. |
stateMismatch | A */set call carried an ifInState that is not the current state. Nothing was changed. |
serverFail | An unexpected error occurred while running the method. Its description is generic text; retrying the same call is expected to fail again. |
Errors on one object
Section titled “Errors on one object”A */set or */copy call that fails on one object still succeeds as a call. The failure is reported for that object in notCreated, notUpdated or notDestroyed (and notCopied for a copy), keyed by the creation id or the object id, and the other objects in the call are processed (RFC 8620 section 5.3).
{ "notUpdated": { "mb-123": { "type": "invalidProperties", "description": "...", "properties": ["name"] } }}| Property | Meaning |
|---|---|
type | Always present: the kind of failure, for example forbidden, notFound, invalidProperties or alreadyExists. |
description | Optional text for debugging. |
properties | With invalidProperties: the names of the properties that were invalid. |
existingId | With alreadyExists: the id of the object that already carries the conflicting value. |
Result references
Section titled “Result references”A key JMAP feature is the ability to use the output of one method call as the input to a later call in the same request. This avoids a round-trip. To reference a result, prefix the argument key with # and provide a ResultReference object:
{ "resultOf": "<clientId of the earlier call>", "name": "<method name of the earlier call>", "path": "/path/to/value"}Example: list and fetch emails in one request
Section titled “Example: list and fetch emails in one request”This example:
- Queries the 10 most recent emails in the Inbox
- Fetches the subject, from, and preview of those emails — in the same HTTP request, without needing the IDs from step 1 first
# Substitute your accountId from the session objectACCOUNT_ID="acc-abc123"INBOX_ID="mailbox-inbox-id" # obtain via Mailbox/get
curl -s -X POST "https://jmap.mail.example.com/jmap" \ -H "Authorization: Bearer $TOKEN" \ -H "Content-Type: application/json" \ -d '{ "using": ["urn:ietf:params:jmap:core", "urn:ietf:params:jmap:mail"], "methodCalls": [ ["Email/query", { "accountId": "'"$ACCOUNT_ID"'", "filter": { "inMailbox": "'"$INBOX_ID"'" }, "sort": [{ "property": "receivedAt", "isAscending": false }], "limit": 10 }, "q1"],
["Email/get", { "accountId": "'"$ACCOUNT_ID"'", "#ids": { "resultOf": "q1", "name": "Email/query", "path": "/ids" }, "properties": ["subject", "from", "preview", "receivedAt"] }, "g1"] ] }' | jq '.methodResponses[1][1].list'Example: fetch all mailboxes
Section titled “Example: fetch all mailboxes”curl -s -X POST "https://jmap.mail.example.com/jmap" \ -H "Authorization: Bearer $TOKEN" \ -H "Content-Type: application/json" \ -d '{ "using": ["urn:ietf:params:jmap:core", "urn:ietf:params:jmap:mail"], "methodCalls": [ ["Mailbox/get", { "accountId": "'"$ACCOUNT_ID"'", "ids": null }, "m1"] ] }' | jq '.methodResponses[0][1].list[] | {id, name, role}'Example: incremental sync with Email/changes
Section titled “Example: incremental sync with Email/changes”After your initial sync (via Email/get with ids: null), use the state value from the response to poll for changes incrementally:
curl -s -X POST "https://jmap.mail.example.com/jmap" \ -H "Authorization: Bearer $TOKEN" \ -H "Content-Type: application/json" \ -d '{ "using": ["urn:ietf:params:jmap:core", "urn:ietf:params:jmap:mail"], "methodCalls": [ ["Email/changes", { "accountId": "'"$ACCOUNT_ID"'", "sinceState": "<state-from-previous-response>" }, "c1"],
["Email/get", { "accountId": "'"$ACCOUNT_ID"'", "#ids": { "resultOf": "c1", "name": "Email/changes", "path": "/created" }, "properties": ["subject", "from", "mailboxIds", "receivedAt"] }, "g1"] ] }' | jq .If hasMoreChanges is true in the changes response, call again with the returned newState until it is false.
ServerlessInbox offers two push channels. Both deliver a hint that something changed, never the data itself.
PushSubscription(RFC 8620 §7.2) registers an HTTPS endpoint that the server calls on each change, optionally with an encrypted body. See the PushSubscription reference. It requires thepush/manageright.- The WebSocket channel keeps a connection open and sends a
stateChangeframe, described below. It is ServerlessInbox’s own protocol, specified athttps://specs.serverlessinbox.com/websocket, not the JMAP WebSocket transport of RFC 8887.
JMAP push over WebSocket (RFC 8887) is not implemented: that RFC multiplexes full JMAP API requests and responses over the WebSocket connection, replacing HTTP, which this server deliberately avoids (see Push Notifications). The EventSource transport of RFC 8620 §7.3 is not served either, because holding a stream open per client would bill compute for the whole time the stream is open. A client that wants push uses PushSubscription or the WebSocket channel, and otherwise polls */changes.
Both channels carry only the data types a client can track with */changes: Mailbox, Email, Thread, EmailDelivery, Identity, EmailSubmission, AddressBook, ContactCard, Principal, ShareNotification and SieveScript. Each is cut to the types the client subscribed to.
WebSocket push
Section titled “WebSocket push”To use the WebSocket channel, a client has to:
- Read the session object’s
capabilitiesmap for the vendor keyhttps://specs.serverlessinbox.com/websocket— this is how a client discovers push is available at all, and where; itsurlfield (e.g.wss://ws.mail.example.com) is the WebSocket endpoint (thewssubdomain, following the samesubdomainNamespacelogic as the other endpoints). - Connect and send a
subscribeframe naming theaccountIdand data types to watch. - On each
stateChangeframe, call the relevant JMAP*/changesmethod over the normal HTTPapiUrlto fetch the delta — the WebSocket carries only the “something changed” signal, never JMAP request/response data itself.
Per RFC 8620 §7.2 (hint-only push), treat this the same way: a missed or dropped stateChange notification is not a correctness bug — a client must still be able to recover by polling */changes with its last known state. See the WebSocket Events reference for the full message protocol.
Concretely, the WebSocket channel only carries a small custom JSON protocol (subscribe → subscribed/error, and server-pushed stateChange notifications naming which JMAP data types changed) — it is not a transport for JMAP method calls. On receiving a stateChange, a client still issues an ordinary HTTP /changes or /query call to fetch the actual data. This is a hint channel only, consistent with RFC 8620 §7.2’s requirement that clients handle missed push notifications by polling: if a WebSocket message is dropped or the connection drops, the client must recover by polling anyway, so treat the WebSocket channel as an optimization, never as the sole sync mechanism.
What this means for a third-party JMAP client
Section titled “What this means for a third-party JMAP client”A generic, off-the-shelf JMAP client that assumes the full RFC 8620/8621 method set will not work unmodified against ServerlessInbox — see Method coverage above for the complete list of what’s available. In short: a client that hard-requires Core/echo, EventSource or RFC 8887 WebSocket push will not be fully functional out of the box. A client that sticks to mail-object CRUD/query/changes and treats push as an optional hint — using PushSubscription or the WebSocket channel, and polling when push is unavailable — should interoperate normally.