jmap.dev

How JMAP tells apps about new mail

A JMAP server never sends the new mail itself. It sends a short notice that something changed, and the app then asks for just the changes. There are three ways to get that notice.

WayHow it worksBest for
EventSourceThe app keeps one https connection open and the server writes a line when something changesDesktop and web apps that stay open
Web PushThe server posts the notice to an address the app gave it, even when the app is closedPhone apps and browsers
WebSocket (RFC 8887)Requests and notices share one open connectionBusy apps that send lots of requests

Why phones are different

iPhones and Android phones close apps in the background, so an open connection doesn't last. Instead, the app gives the server a Web Push address, often a small relay run by the app's maker, which turns the notice into a normal phone alert. The notice only says "something changed", and servers can encrypt it, so the relay never sees your mail.

Does my server support it?

Run the checker with a token. It shows whether the session offers EventSource, Web Push and WebSocket.

Check push support

What the notice looks like

Whichever way it arrives, the notice is the same small piece of JSON, called a StateChange. It lists each account that changed and, for each kind of data, its new state string:

{
  "@type": "StateChange",
  "changed": {
    "A1": {
      "Email": "d35ecb040aab",
      "Mailbox": "0af7a512ce70",
      "Thread": "29fe2e7b1d54"
    }
  }
}

The app compares each state with the one it saved last time. If Email has moved on, it calls Email/changes with its old state and gets back only the ids that were created, updated or destroyed. Nothing in the notice says who the mail is from or what it's about.

How a server says which ways it offers

WayWhere to look in the sessionWhat the app does
EventSourceeventSourceUrl, a link template with {types}, {closeafter} and {ping} to fill inOpens the link and keeps it open. ping asks the server to send a heartbeat so the app can tell a quiet connection from a dead one
Web PushPart of the core standard (RFC 8620), so there's nothing extra to look forCalls PushSubscription/set with its push address. The server first sends a one off code, which the app sends back to prove the address is really its own
WebSocketThe urn:ietf:params:jmap:websocket capability, with a url and supportsPushConnects to that address, then sends WebSocketPushEnable to start getting notices on the same connection

Web Push is in the core standard, but not every server supports all three ways in practice, so check yours with the checker. The capabilities reference covers the WebSocket and Web Push keys capabilities too.

Going further