> ## Documentation Index
> Fetch the complete documentation index at: https://docs.bijection.com/llms.txt
> Use this file to discover all available pages before exploring further.

# Exchange EWS folder sync

> Track metadata from a distinguished Exchange Server mail folder.

Mount `@bijectionhq/app-imap` in EWS mode for on-premises Exchange Server.
The app requests the Exchange 2013 EWS protocol version. The server must
expose a reviewed HTTPS origin with Basic authentication
enabled on `/EWS/Exchange.asmx` and be reachable through the installation's HTTP
egress policy. The app uses the bounded XML bundled parser.
[Exchange Online EWS retirement](https://learn.microsoft.com/en-us/exchange/clients-and-mobile-in-exchange-online/deprecation-of-ews-exchange-online)

## Mount and start

```ts bijection/app.ts theme={"theme":{"light":"github-light-default","dark":"github-dark-default"}}
import { app, label, secret } from "@bijectionhq/bijection";
import mailbox, { exchangeMailboxReceiver } from "@bijectionhq/app-imap";

const inboxes = label();
const login = secret();
const ews = exchangeMailboxReceiver("https://exchange.example.com", login, inboxes);

export default app({ inboxes, login, ews, exchange: mailbox({ data: inboxes, ews }) });
```

Grant `exchange.operator` and call `exchange.source.initialize` with:

```ts theme={"theme":{"light":"github-light-default","dark":"github-dark-default"}}
{ profile: { mode: "ews", mailbox: "reader@example.com", folder: "inbox" } }
```

Read metadata with `exchange.metadata.list`, content with
`exchange.content.get` and the position with `exchange.source.progress`.

Set the base64 encoding of `username:password` with
`bijection secret set login`. Use a principal with read access to the selected
primary SMTP mailbox and distinguished folder. The admitted folders are
`inbox`, `sentitems`, `drafts`, `deleteditems`, `junkemail` and `outbox`.
[Installer-bound labels](https://docs.bijection.com/integrations/native-connectors.md#installer-bound-labels)

## Position and limits

The app uses `SyncFolderItems` with an ID-only shape plus selected metadata
properties. A returned `Message` is keyed by its EWS `ItemId`. The row's
`payload` is JSON text. Explicit deletes withdraw membership and read flag
changes update known messages. Capture applies to Exchange `Message` items. [SyncFolderItems operation](https://learn.microsoft.com/en-us/exchange/client-developer/web-service-reference/syncfolderitems-operation)

The app admits up to 24 changes per SOAP page within the 64 KiB encoded
result budget. It retains at most 4,096 characters of opaque `SyncState` and
commits each page with its state. The initial folder view publishes when
`IncludesLastItemInRange` completes the first round. An invalid held sync
state stops the feed. Use `source.progress` to read `revision` and
`gapAt`, then pass them to `source.reset` for a new baseline. The previous
view stays visible until the replacement baseline finishes. Use
`metadata.list` with the page's `next` as `cursor` to read the next page
of up to 100 rows.

A new baseline has one day to finish, including time spent paused. An
expired baseline keeps the previous view. Reset the source and resume it
if it is paused.

## Message Files

The app requests MIME with `GetItem` using the EWS `ItemId` and
`ChangeKey`. The receiver streams one SOAP response into private
512 KiB File parts. The SOAP reply must echo both identity values before
the parts can be handed to the app. `content.get` returns the raw MIME File and embedded attachment
Files. A message without an admitted ChangeKey remains available as metadata.

The raw MIME and up to 32 attachment Files share an 8 MiB budget. The
receiver hashes the complete decoded body under the original permit.
A changed ID, version, size or digest refuses publication. The app
retires the private parts in the commit that publishes the message Files. Content acquisition
leaves the folder sync position intact on refusal. `content.retry` requests a
fresh raw capture and cleanup retires the previous private staging Files.
[Export MIME with EWS](https://learn.microsoft.com/en-us/exchange/client-developer/exchange-web-services/how-to-export-items-by-using-ews-in-exchange)


This documentation is built and hosted on [Mintlify](https://mintlify.com), a developer documentation platform.