Skip to content

Microsoft 365

The Microsoft 365 source migrates an Exchange Online tenant. Vandelay reads the tenant through Microsoft Graph as an application with application permissions, so it needs no user password and signs in to no mailbox. It reads the directory (users, shared, room and equipment mailboxes, groups and verified domains) and copies each mailbox’s mail, calendars, contacts and OneDrive files, its automatic reply and its inbox rules.

A hosted service cannot be placed behind the Stalwart proxy, because the operator controls neither its network nor its ports, so Microsoft 365 is migrated with a one-shot migration: every account is copied while users keep working in Microsoft 365, and each domain moves at once with its MX records and client settings.

Each user, shared mailbox, room and equipment mailbox becomes a Stalwart account, told apart by the purpose (userPurpose) that Exchange Online reports for each mailbox, with its primary address and its aliases. A mailbox whose purpose is empty, others or unknown is not migrated, and discovery reports it with the mailbox of <user> reports no kind that can be migrated (userPurpose is empty, others or unknown); it is not migrated. An alias in a domain the tenant has not verified is dropped, with alias <alias> of <primary> is in a domain the tenant has not verified. A user whose sign-in is blocked in Entra (accountEnabled is false) is a disabled account: it is migrated only when “Include disabled accounts” (selection.include_disabled) is on, and is then created on Stalwart with sign-in disabled. Shared mailboxes become Stalwart groups, and pre-flight notes that Send As and Send on Behalf rights are not migrated, because the members of a Stalwart group can send from its address. Mail-enabled groups become lists or groups with their members. Guest users and users without a mailbox address are left out.

For each mailbox, Graph serves mail with its folders, read state, flags and categories, calendars with recurring events and their modified occurrences (found within five years before and after the day of the import, the widest span Graph lists; an occurrence edited outside that span arrives with the series’ values), contacts with their photos, and the OneDrive files. The Graph importer page describes how each is carried. The inbox rules become Stalwart mail rules; a rule whose action cannot be expressed on Stalwart, or that moves mail to a folder that was not migrated, is reported, and the rest of the rule is migrated.

The automatic reply becomes the account’s vacation response, with one adjustment. Stalwart answers every sender, so a reply limited to senders inside the organisation or to the user’s contacts, or one without a message for outside senders, is migrated turned off, with its text and dates kept, and the run reports it with a message such as the automatic reply was limited to senders inside the organisation on the source; Stalwart cannot limit it, so it was migrated turned off; turn it on to reply to every sender. A reply to every sender with separate internal and external messages migrates turned on, with the external message.

Microsoft Entra exposes no password hashes, so every account gets a temporary password, or signs in through an external identity provider, as chosen in Passwords. No DKIM keys are read either; provisioning generates new ones, as described in DKIM keys.

Prepare the tenant by registering an application, granting it the permissions below and giving Vandelay a credential for it. The same steps are printed by vandelay migrate guide m365 and shown beside the Source: access step in the web and terminal interfaces.

  1. Register the application. In the Microsoft Entra admin center, open App registrations and choose New registration. Any name will do; keep “Accounts in this organizational directory only”, and leave the redirect URI empty.
  2. Copy its identifiers. The Overview page of the registration shows the Directory (tenant) ID and the Application (client) ID, which become the source’s tenant and client id below.
  3. Add the permissions. Under API permissions, choose Add a permission, Microsoft Graph, Application permissions, and add every permission listed in Permissions. The delegated User.Read that a new registration carries can be removed.
  4. Grant admin consent. Choose Grant admin consent for the tenant. Until consent is granted, the application’s token carries no permissions, and Vandelay can read nothing. Granting consent for Microsoft Graph application permissions needs a Privileged Role Administrator or a Global Administrator; the Application Administrator and Cloud Application Administrator roles cannot grant Graph application permissions, as Grant tenant-wide admin consent explains.
  5. Add a credential. Under Certificates & secrets, either create a client secret and copy its value, which Entra shows only once, or upload the PEM certificate whose private key Vandelay will use. A client secret expires, after at most two years, so it must outlast the migration.

Vandelay needs these Microsoft Graph application permissions, all of them:

  • User.Read.All, to list the users
  • Domain.Read.All, to list the verified domains
  • GroupMember.Read.All, to list groups and their members
  • Mail.Read, to read mail
  • MailboxSettings.Read, to read each mailbox’s purpose, its automatic reply and its inbox rules
  • Calendars.Read, to read calendars
  • Contacts.Read, to read contacts
  • Files.Read.All, to read OneDrive files

A broader permission covers a narrower one: Directory.Read.All covers the user, domain and group permissions, Group.Read.All covers group members, Sites.Read.All covers files, and the ReadWrite variants cover their Read counterparts. Vandelay only reads from the tenant, even when a ReadWrite permission is granted. The connection test reads the permissions from the application’s access token and names any that are missing.

Two more permissions are optional. Place.Read.All lets Vandelay read the capacity of room mailboxes; without it, rooms are migrated without a capacity, and the discovery log says room capacities are not available (<error>); rooms are migrated without a capacity. Member.Read.Hidden lets it read the members of groups whose membership is hidden; without it, each such group is reported with the members of group <group> are hidden from the app (Member.Read.Hidden); its memberships are not migrated.

Limiting the application to some mailboxes

Section titled “Limiting the application to some mailboxes”

Application permissions reach every mailbox in the tenant. To limit the application, an Exchange administrator scopes it in Exchange Online with an application access policy, which can take more than an hour to apply to Microsoft Graph. The policy covers mail, calendars, contacts and mailbox settings, not OneDrive files or the directory. RBAC for Applications does not suit Vandelay: it limits the application only once the Microsoft Graph permissions are removed from the app registration, and Vandelay then finds them missing from its token. A mailbox outside that scope cannot be read: discovery reports it with the mailbox of <user> is not readable by the app; check application access policies, and it is not migrated. Discovery fails only when no mailbox at all is readable.

“Tenant” (source.tenant, --tenant) is the Directory (tenant) ID, or a verified domain of the tenant such as example.onmicrosoft.com. The shared authorities common, organizations and consumers cannot sign in an application, and are refused. “Application (client) id” (source.client_id, --client-id) is the Application (client) ID. The tenant is bound once work starts.

The credential is exactly one of two:

  • “Client secret” (source.client_secret, --client-secret), a secret reference to the secret’s value: env:NAME, file:PATH, or ask to be asked for at a prompt. The runner keeps the answer in memory until it stops, so a runner that starts unattended needs env: or file:.
  • “Certificate” (source.certificate.certificate, --certificate), the PEM certificate file, with “Certificate private key” (source.certificate.key, --certificate-key), a reference to its PEM private key. The key comes from env: or file:; ask is refused with Certificate private key cannot be ask: the key spans several lines and cannot be typed at a prompt; give file:PATH (the key file on the vandelay host) or env:NAME. Both are read on the host where Vandelay runs, so their paths name files on that host. On the Source: access step, the private key field appears only after the certificate file is saved: save with the certificate set, which reports the private key as required, then fill in the key and save again. On the command line, --certificate=PATH --certificate-key=file:PATH sets both at once.

The following command sets a Microsoft 365 source with a client secret:

Terminal window
vandelay migrate source --system=m365 \
--tenant=example.onmicrosoft.com \
--client-id=11111111-2222-3333-4444-555555555555 \
--client-secret=env:VANDELAY_M365_SECRET

The same settings in plan.toml:

[source]
system = "m365"
tenant = "example.onmicrosoft.com"
client_id = "11111111-2222-3333-4444-555555555555"
client_secret = "env:VANDELAY_M365_SECRET"

With a certificate, the secret is replaced by the certificate table:

[source]
system = "m365"
tenant = "example.onmicrosoft.com"
client_id = "11111111-2222-3333-4444-555555555555"
certificate = { certificate = "certs/vandelay.pem", key = "file:certs/vandelay.key" }

Microsoft Graph throttles clients that send too many requests to one mailbox or one tenant. Vandelay keeps to at most four concurrent requests per mailbox and 32 per tenant, and when Graph answers that a request is throttled, it waits for the time Graph names in Retry-After before sending again. A large tenant is therefore copied at the pace Microsoft allows, and starting the first copy well before the planned change leaves room for it.

Discovery reports these losses for every Microsoft 365 project:

  • Mailbox-level forwarding: mailbox-level forwarding (Exchange ForwardingSmtpAddress) cannot be read through Microsoft Graph and is not migrated; inbox rules that forward are migrated; check with 'Get-Mailbox | Where ForwardingSmtpAddress' and set it on Stalwart. Run that command in Exchange Online PowerShell, with -ResultSize Unlimited after Get-Mailbox in a tenant of more than 1,000 mailboxes, to find the mailboxes that forward, and set their forwarding on Stalwart by hand.
  • FullAccess and Send As permissions, folder permissions and delegates (Send on Behalf), which are granted and shared again on Stalwart.
  • Outlook item attachments: an attached message, event or contact keeps its content, but not the name Outlook shows for it, because Graph’s MIME form of a message does not carry it.

Microsoft 365 groups are migrated without their content. Graph’s application access cannot read a group mailbox, so their conversations, calendar and files stay behind, and each group is reported. On Stalwart the group is a group mailbox with its address and members, so after the change new mail to the group lands there.

Online archive mailboxes and public folders are not read through Graph. While the tenant still allows EWS, they are copied with the per-account EWS importer and the export, into the accounts the migration created; Microsoft is retiring EWS in Exchange Online, as that page describes.

Accounts that Graph serves no mailbox for, because they are not licensed for Exchange, are mail users, are hosted on premises, are inactive or are still being provisioned, are reported and not migrated; one that Exchange is still provisioning is picked up by a later run.

The change of a domain follows One-shot migration, with three points specific to Microsoft 365.

Before the change, publish the records Stalwart needs: the DKIM keys that provisioning generated, SPF and DMARC records that authorise Stalwart, MTA-STS, and the autoconfig and Autodiscover names, as Records to change lists. Lower the TTL of the MX records a day in advance, so that sending servers follow the change quickly.

Users’ clients need to be set up again. Outlook, phones and tablets configured with a Microsoft 365 or Exchange account type keep connecting to Microsoft after the MX change, whatever the DNS says, so each user removes that account and adds the Stalwart account, with the temporary password or the external sign-in. vandelay migrate export-users and vandelay migrate guide mail-merge prepare the message to send them, as User communication describes.

Keep the tenant active until the catch-up passes have run for every account. Until then the domain can still be returned to Microsoft 365 by restoring its MX records and client settings, but Vandelay cannot undo the switch (see No rollback): mail that Stalwart received after the change exists only on Stalwart, and has to be carried back separately, for example by users moving it with a client connected to both services.