Skip to content

Mail

JMAP for Mail (RFC 8621) is the mail part of JMAP, the JSON protocol over HTTP that Stalwart also uses for calendars, contacts, files and its own management API. A JMAP mail client reads and changes mailboxes, messages and threads with method calls such as Mailbox/get, Email/query and Email/set, sends mail with EmailSubmission/set instead of a separate SMTP connection, and learns of changes through push notifications for the whole account. It suits webmail and clients built for it: one connection replaces the IMAP connection per folder and the SMTP submission session, and the client synchronises by asking for the changes since the state it last saw.

This page describes the mail side of JMAP. The protocol itself, with its endpoints, request limits, push notifications and WebSocket transport, is described in the JMAP overview and the pages that follow it, and applies to every kind of data. The mailboxes and messages that JMAP clients see are the same ones IMAP, POP3 and Exchange clients see, as described in Mailboxes, messages and flags.

A client learns what the server offers from the capabilities in the session resource. The mail capabilities are the following:

  • urn:ietf:params:jmap:mail, for mailboxes, messages, threads and search
  • urn:ietf:params:jmap:submission, for identities and sending
  • urn:ietf:params:jmap:vacationresponse, for the automatic reply
  • urn:ietf:params:jmap:mdn (RFC 9007), for read receipts
  • urn:ietf:params:jmap:mail:share, for sharing mailboxes with other accounts
  • urn:ietf:params:jmap:emailpush, for message contents in push notifications

JMAP capabilities lists them with the rest, and describes which permission each requires and which are hidden on accounts that another user shares. Sending, read receipts and the vacation response are offered only on the user’s own account and on the groups the user belongs to, never on an account shared with the user.

The mail capability publishes limits that clients use to avoid requests the server would refuse. They are taken from the Email singleton: maxMailboxesPerEmail from the field of the same name, maxMailboxDepth from maxMailboxDepth, maxSizeMailboxName from maxMailboxNameLength and maxSizeAttachmentsPerEmail from maxAttachmentSize. Message and mailbox limits describes them. The capability also lists the sort orders Email/query accepts: receivedAt, size, from, to, subject, sentAt, hasKeyword, allInThreadHaveKeyword and someInThreadHaveKeyword.

Mailboxes are managed with Mailbox/set. The inbox, the junk folder and the trash are permanent, and an attempt to destroy one fails with forbidden, You are not allowed to delete Inbox, Junk or Trash folders. A mailbox that still has child mailboxes cannot be destroyed either (mailboxHasChild). A mailbox that still contains messages is refused with mailboxHasEmail unless the request sets onDestroyRemoveEmails, in which case its messages are removed with it: a message that is also in other mailboxes stays in those, and a message in this mailbox only is destroyed.

In an account that another user shares, a sharee cannot create mailboxes at the top level, and receives You are not allowed to create root folders.; it can create child mailboxes where it holds the right to, as described in Shared mailboxes.

A message can belong to several mailboxes at once, listed in its mailboxIds, and every message must belong to at least one. Messages enter the account in three ways besides delivery: Email/set creates one from its parts, Email/import stores a complete message previously uploaded as a blob, and Email/copy copies one from another account. An import is refused with invalidEmail, Blob does not contain a valid RFC 5322 message., when the blob is not a message, and with invalidProperties, Message must belong to at least one mailbox., when no mailbox is given. Imported messages are checked against the same message limits as messages received over SMTP.

Email/set destroys a message outright: it is removed from every mailbox, not moved to the trash. Clients that offer a trash folder move the message there by changing its mailboxIds, and the server’s auto-expunge empties the trash later. Adding $junk or $notjunk, or moving a message into or out of the junk folder, trains the spam classifier, as described in Flags and keywords.

SearchSnippet/get returns, for each message of a search result, the parts of the subject and body that matched, with every match wrapped in <mark> and </mark>. The snippets come from the text, subject and body conditions of the filter; a search on other properties, such as from, produces no snippet. Matching follows the same rules as the search itself, including stemming. The language used for stemming is detected from the search terms, and falls back to defaultLanguage on the Search singleton; a term prefixed with a language code, such as de:Rechnung, forces that language.

A request may ask for snippets of at most maxSnippetResults messages, described in JMAP limits.

An identity is an address the user may send from, with a display name and signatures. Stalwart creates the identities of an account itself, one for each of the account’s addresses, including its domain aliases and the addresses of the groups it belongs to. The name of a new identity is the account’s description, or its name when it has no description. The server keeps the list in step with the account: when an address is added, its identity appears the next time a client reads the identities, and when an address is removed, the identities that no longer resolve to the account are deleted.

Users can add identities of their own, for example a second identity for the same address with a different name or signature. The address of a new identity must be one of the account’s addresses; any other address is refused with invalidProperties, E-mail address not configured for this account. The number of identities per account is bounded by maxIdentities.

A client sends a message by creating an EmailSubmission that names the message, already stored as a draft, and the identity to send it as. The server hands the message to its own SMTP submission pipeline, inside the server, as if the client had submitted it over SMTP with the account’s credentials. Everything that applies to SMTP submission therefore applies to JMAP as well: the sender checks, the MAIL FROM and RCPT TO stages with their Sieve scripts, milters and rate limits, DKIM signing and the outbound queue.

The envelope is checked against the identity before anything is queued. The envelope sender must be the identity’s address, compared without regard to case, or the submission fails with forbiddenFrom, Envelope mailFrom does not match identity email address. When the client gives no envelope, the sender is the identity’s address and the recipients are taken from the To, Cc and Bcc headers of the message; with none, the submission fails with noRecipients, No recipients found in email. The Bcc header is removed from the message before it is queued, so recipients never see it.

A rejection by the SMTP pipeline is reported with the SMTP reply. A refusal at MAIL FROM, for example a sender address that does not belong to the account, fails the submission with forbiddenMailFrom and the description Server rejected MAIL-FROM: <reply>, and a refusal of the message itself with forbiddenToSend, Server rejected DATA: <reply>. A recipient that is refused does not fail the submission: the message is queued for the others, and the refused recipient appears in deliveryStatus with delivered set to no and the SMTP reply. Only when every recipient is refused is nothing queued.

After queuing, deliveryStatus follows the message through the queue. delivered is queued while delivery to a recipient is pending or being retried, yes once it has succeeded and no once it has failed permanently. undoStatus is pending while the message is in the queue and final once it has left it. The number of submissions an account keeps is bounded by maxSubmissions, and old submissions are removed after expungeSubmissionsAfter; a client that reaches the limit receives overQuota, There are too many email submissions, please delete some before adding a new one.

A client usually also asks the server to update the message once it is sent, for example to move it from Drafts to Sent, through onSuccessUpdateEmail, or to delete it through onSuccessDestroyEmail. Both are honoured.

A client can schedule a message for later with the HOLDUNTIL or HOLDFOR parameter of the FUTURERELEASE extension (RFC 4865) in the envelope sender, and the message waits in the queue until then. The submission capability advertises maxDelayedSend as 30 days, but the limit that applies is the SMTP futureRelease setting, as described in SMTP extensions; a longer hold fails with forbiddenMailFrom and the SMTP reply. The other extensions the capability lists, SIZE, DSN, DELIVERYBY, MT-PRIORITY and REQUIRETLS, are likewise subject to the SMTP settings.

A message that is still in the queue can be recalled by setting its undoStatus to canceled, which removes it from the queue. Once the message has left the queue, the request fails with cannotUnsend, The requested message is no longer in the queue. Destroying an EmailSubmission only deletes the record; it does not stop the delivery.

A sender can ask for a read receipt, a message disposition notification (RFC 8098), and the recipient’s client decides whether to send one. With the mdn capability, a JMAP client sends the receipt with MDN/send and parses received receipts with MDN/parse. Sending a receipt requires the emailSend permission in addition to the JMAP permissions, since it sends mail.

The vacation response is the automatic reply for a user who is away, managed through the VacationResponse singleton. Each account has exactly one: clients update it, and cannot create or destroy it. The subject must be shorter than 512 bytes, and each of the text and HTML bodies shorter than 2048 bytes.

Stalwart implements the reply with Sieve, in the account’s managed script, which has consequences for users who also run Sieve filters of their own; Vacation responses describes them. In short, enabling the vacation response can replace the user’s own active script, and isEnabled reads false whenever the managed script is not running, whatever was set.

Each JMAP method on each object is governed by a permission of its own, for example jmapEmailGet, jmapEmailImport, jmapEmailSubmissionCreate or jmapVacationResponseUpdate, and a capability is listed only to accounts that hold the permission it requires. Removing a permission from a role therefore withdraws the corresponding feature from its users, for example jmapEmailSubmissionCreate to stop them sending through JMAP. Requests authorised with an OAuth token need the mail scope for every mail capability. The full list of permissions is in the permissions reference.