JMAP by example
Real requests for the jobs every mail app does, with notes on each part. Try any of them in the playground. Ids like A1 stand in for your own.
Fetch the session
Every app starts here. The reply gives your account ids and the apiUrl that all the requests below go to.
curl -H "Authorization: Bearer YOUR_TOKEN" https://api.fastmail.com/jmap/sessionEach request after that is a POST to the apiUrl with the same header and a JSON body.
List folders
{
"using": ["urn:ietf:params:jmap:core", "urn:ietf:params:jmap:mail"],
"methodCalls": [
["Mailbox/get", { "accountId": "A1", "ids": null }, "m"]
]
}"ids": null means all of them. Each mailbox has a role (inbox, sent, drafts, trash) so you can find them whatever they're called.
Newest mail in the inbox
{
"using": ["urn:ietf:params:jmap:core", "urn:ietf:params:jmap:mail"],
"methodCalls": [
["Email/query", {
"accountId": "A1",
"filter": { "inMailbox": "INBOX_ID" },
"sort": [{ "property": "receivedAt", "isAscending": false }],
"limit": 20
}, "q"],
["Email/get", {
"accountId": "A1",
"#ids": { "resultOf": "q", "name": "Email/query", "path": "/ids" },
"properties": ["from", "subject", "receivedAt", "preview", "keywords"]
}, "g"]
]
}Two steps, one trip. The #ids back reference hands the first step's ids to the second, so you don't wait for one reply before sending the next request.
Search
Swap the filter for a search. text looks everywhere; from, subject and body look in one place.
"filter": { "text": "invoice", "after": "2026-01-01T00:00:00Z" }Mark as read
{
"using": ["urn:ietf:params:jmap:core", "urn:ietf:params:jmap:mail"],
"methodCalls": [
["Email/set", {
"accountId": "A1",
"update": { "M123": { "keywords/$seen": true } }
}, "r"]
]
}The keywords/$seen path changes just that one flag and leaves the others alone. Use null to mark it unread again.
Move a message
"update": { "M123": { "mailboxIds": { "ARCHIVE_ID": true } } }Setting mailboxIds as a whole moves it. To add a label but keep it where it is, use "mailboxIds/LABEL_ID": true instead.
Send a message
{
"using": ["urn:ietf:params:jmap:core", "urn:ietf:params:jmap:mail", "urn:ietf:params:jmap:submission"],
"methodCalls": [
["Email/set", {
"accountId": "A1",
"create": { "draft": {
"mailboxIds": { "DRAFTS_ID": true },
"keywords": { "$draft": true, "$seen": true },
"from": [{ "email": "sam@example.org" }],
"to": [{ "email": "alex@example.com" }],
"subject": "Hello",
"bodyValues": { "b": { "value": "Hi Alex" } },
"textBody": [{ "partId": "b", "type": "text/plain" }]
} }
}, "c"],
["EmailSubmission/set", {
"accountId": "A1",
"create": { "send": { "identityId": "IDENTITY_ID", "emailId": "#draft" } },
"onSuccessUpdateEmail": { "#send": {
"mailboxIds/DRAFTS_ID": null,
"mailboxIds/SENT_ID": true,
"keywords/$draft": null
} }
}, "s"]
]
}First the message is saved as a draft, then it's sent. #draft refers to the draft made a moment earlier in the same request, and onSuccessUpdateEmail moves it to Sent once it's gone. Get IDENTITY_ID from Identity/get.
Catch up on changes
["Email/changes", { "accountId": "A1", "sinceState": "STATE_YOU_SAVED", "maxChanges": 200 }, "c"]Every /get reply includes a state. Save it, and next time ask for changes since then. You get lists of created, updated and destroyed ids, plus a newState. If hasMoreChanges is true, ask again from the new state. If the server answers cannotCalculateChanges, fetch everything again.
Words you don't know? See the glossary.