Skip to content

Configuration

Exchange support needs little configuration of its own. One switch enables every Exchange protocol, and a handful of limits bound what a client may send. Most of the work lies elsewhere: making the global address list visible, deciding who sees whose free/busy time, and making sure that authentication and any reverse proxy suit the way Exchange clients sign in. This page covers each of these in turn.

The protocols are controlled by the Exchange singleton, found in the WebUI under Settings › Network › Exchange. Its enable field is disabled on a new installation. The following call turns it on:

Terminal window
stalwart-cli update Exchange --field enable=true

The switch covers MAPI over HTTP, EWS, ActiveSync, the offline address book and the Exchange form of Autodiscover together; there is no setting for a single protocol. Like most settings, it takes effect when the settings are reloaded with the ReloadSettings action, with no restart, as described in Applying changes.

The official releases and the Docker image include Exchange support. A server compiled from source includes it only when the exchange Cargo feature is selected, which the default build does, as described in Compiling Stalwart; a binary built without it ignores the switch and behaves as if it were off.

While the switch is off, requests to the Exchange paths receive 404 (a request for the bare /Microsoft-Server-ActiveSync path is first redirected to the same path with a trailing slash), and Autodiscover gives the IMAP, POP3 and SMTP answer described in Autoconfiguration. No account needs a permission of its own to use the Exchange protocols once they are enabled: any account that may sign in can connect, and it reaches the same data that it reaches over IMAP, JMAP and DAV. Reading and changing the Exchange object requires the sysExchangeGet and sysExchangeUpdate permissions.

Enabling Exchange also changes how the server reads HTTP Basic credentials, on every HTTP endpoint and not only on the Exchange paths. Two client habits make this necessary:

  • Windows clients send credentials in the Windows-1252 code page rather than UTF-8. When the decoded credentials are not valid UTF-8, the server decodes them as Windows-1252, so passwords with accented characters work.
  • Outlook and other Windows clients often send the login as DOMAIN\user, the form used by Active Directory. The server removes everything up to the last backslash and signs in with the rest.

JMAP, CalDAV, CardDAV and WebDAV clients that use Basic authentication see the same relaxed decoding while Exchange is enabled. IMAP, POP3, SMTP and ManageSieve are not affected.

EWS clients adapt their requests to the Exchange version that the server reports. ewsVersion selects that version: Exchange 2010 SP2, 2013, 2013 SP1 or 2016, with exchange2016 as the default. The setting changes only the version information in EWS responses and in the SOAP form of Autodiscover, not the operations the server implements, so it needs changing only for a client that refuses to work with a newer version.

Exchange clients send large requests and hold long-running ones, so four limits bound what one client may do. They are decisions about size and duration, and the defaults suit most deployments.

maxRequestSize, 50 MiB by default, caps the body of one MAPI, EWS, ActiveSync or SOAP Autodiscover request. EWS and ActiveSync clients upload a new message, attachments included, inside one request, and EWS encodes it in base64, which adds a third to its size. The limit therefore has to be well above the largest message that users may send, or such messages fail to upload. A larger request is refused with 413 on ActiveSync, with MAPI response code 9 (request too large) on MAPI over HTTP, and with 400 and the detail The request is larger than the server is willing to process. on EWS and SOAP Autodiscover. The XML form of Autodiscover, and SOAP Autodiscover without credentials, accept at most 8 KiB whatever the setting.

maxObjectSize, 256 KiB by default, caps the Exchange-only properties that the server keeps for one item or folder: the extended properties, named properties and client data that Outlook stores and that no standard protocol carries. It does not limit the message itself. A save that would exceed it is refused: Outlook receives ecQuotaExceeded, EWS clients ErrorMessageSizeExceeded, and ActiveSync silently drops flag and category changes beyond the limit. These properties count towards the account’s disk quota, as the messages do.

maxDevices is the number of ActiveSync devices one account may register, 16 by default. When a new device connects to an account at the limit, the server makes room by removing a device that has not connected for at least seven days; only when there is none does the new device receive ActiveSync status 177 (maximum devices reached). Lowering the limit does not remove registered devices at once: when the next new device connects, the server removes devices idle for at least seven days until the account is below the new limit, and refuses the new device if there are not enough of them. Mobile devices describes how devices are registered and removed.

maxHeartbeat is the longest time that a client may wait for changes in a single request. The default and the highest allowed value is 59 minutes, and the shortest allowed value is one minute. The setting bounds three kinds of request:

  • ActiveSync Ping and Sync requests. A device that asks for a longer or shorter wait receives a status that gives the allowed value.
  • EWS streaming subscriptions. The client chooses a connection timeout, which the server shortens to the heartbeat and to at most 30 minutes.
  • Outlook’s MAPI over HTTP notification wait, which never lasts longer than five minutes.

A longer heartbeat means fewer requests per device, so a lower value suits only networks or proxies that close idle connections sooner.

Every request from an Exchange client counts towards the account’s limit of concurrent HTTP requests, the JMAP setting maxConcurrentRequests, which is 4 by default. EWS streaming and Outlook’s notification wait stop counting as soon as the response starts, but an ActiveSync Ping or Sync that waits for changes keeps its slot until it answers, up to the heartbeat. A device does not end its previous wait when it sends a new one, so a user with several phones and tablets can use every slot. Further requests from that account then fail with 400 and the detail The request exceeds the maximum number of concurrent requests. until a wait ends.

Deployments where users have several ActiveSync devices need a higher limit, or the unlimitedRequests permission for those accounts, which lifts the limit. Exchange requests also count towards the HTTP rateLimitAuthenticated rate limit, which answers 429 when it is exceeded.

The server keeps an in-memory cache for the Exchange protocols. It holds per-account Exchange state, such as the identifiers that Exchange clients use for folders and items, the named property mappings that Outlook registers, the category list and the registered ActiveSync devices. Its size is set by Cache.exchange, 32 MiB by default. Like the other caches it is sized at startup, so a change takes effect after a restart. Sizing the caches describes how cache sizes are chosen.

EWS notification subscriptions live in the memory of the node that created them, so a restart ends them, and a request that reaches another cluster node does not find them; the client then subscribes again. An account may hold at most 32 EWS subscriptions on a node, and a node at most 16384 subscriptions and MAPI session entries in all. A subscription beyond these limits is refused with The account has too many subscriptions. or The server cannot hold more subscription state right now.

Outlook’s MAPI over HTTP sessions are kept in the in-memory store, so with Stalwart Keep or Redis they survive a restart and every node finds them. Two parts stay on the node that serves the session: a per-session cache of opened messages, and the items that Outlook has opened for editing but not yet saved. When a node has no room for them, the unsaved items are dropped and the server logs a limit.memory-budget event with MAPI staged objects dropped.

In a cluster, the load balancer should therefore send the requests of one client to the same node, so that EWS subscriptions and unsaved Outlook items are found. Only the response that creates an EWS subscription sets the cookie X-BackEndOverrideCookie to the node’s identifier, which a load balancer that routes on cookies can use for this purpose.

Outlook shows the other users of the organisation in the global address list, through NSPI and the offline address book, and EWS and ActiveSync clients search the same list when resolving names. The list contains every account, group, resource and mailing list with an address on a domain of the server, or of the user’s own tenant when tenants are used, up to 100000 entries.

Listing every account is a directory query, and directory queries are disabled by default, for the reasons given in Sharing. While they are disabled, users without the sysAccountQuery permission see only themselves and the accounts they have access to, and no offline address book is offered to them. For a full address book in Outlook, enable allowDirectoryQueries on the Sharing object. Autodiscover and DNS describes how the offline address book is built and refreshed.

Outlook’s scheduling assistant, and the availability lookups of EWS and ActiveSync clients, show the free/busy time of colleagues when a meeting is planned. In an Exchange organisation every user sees the free/busy time of every other user by default, without sharing a calendar. Calendar.shareFreeBusy gives Stalwart the same behaviour: while it is enabled, every account may read the free/busy time of the other accounts in its tenant, or of every account on the server when tenants are not used. Event details still require a calendar share. The setting applies to JMAP and CalDAV availability queries as well, as described in Free/busy and availability. Disabling it restores the rule that free/busy time is visible only through a share.

The Exchange endpoints accept HTTP Basic authentication and OAuth bearer tokens. NTLM and Kerberos are not available, so Windows clients cannot sign in with the Windows session, and every client asks for the email address and a password.

The 401 challenge that the Exchange endpoints and Autodiscover send offers only Basic authentication, unless the request carried a bearer token, in which case it offers bearer and Basic. Outlook and the Apple clients fail to sign in when a challenge offers a scheme that they cannot complete, which is why the other HTTP endpoints keep offering both. Anonymous requests to the XML and SOAP forms of Autodiscover receive 401 as well, because the answer depends on the account; these responses do not count towards authentication bans.

The user name is the account’s email address, as for any other client. Accounts that use two-factor authentication sign in from Exchange clients with an app password, since none of these clients can complete a second factor over Basic authentication. When such an account signs in with its account password, the server answers 402 with MFA code required instead of 401. A bearer token used on the Exchange endpoints needs at least one of the mail, calendars, contacts or files scopes; a token without any of them receives 403.

Behind a reverse proxy, the proxy must forward the Exchange paths to Stalwart together with the Authorization header:

  • /autodiscover/ (any capitalisation), on the mail host and on autodiscover.<domain>
  • /EWS/
  • /mapi/
  • /Microsoft-Server-ActiveSync
  • /OAB/

Several of these requests stay open for a long time, and they differ in how much they send while they wait. An ActiveSync Ping or Sync sends nothing until it answers, which can take up to the maxHeartbeat. EWS streaming subscriptions send a keep-alive every 45 seconds, and Outlook’s MAPI over HTTP requests send a pending marker every 30 seconds. The proxy’s read timeout for /Microsoft-Server-ActiveSync must therefore be longer than the heartbeat, or the proxy closes the requests before the server answers and devices fall back to frequent reconnection; for the other paths, a read timeout of one minute or more is enough. The proxy should also pass responses through as they are produced rather than buffer them: EWS streaming delivers each notification as a part of one long response, and a buffering proxy holds them back until the response ends. The URLs that Autodiscover hands out are built from the server’s public URL, which must therefore be the address that clients reach through the proxy.