Migrations from Microsoft 365
Configure the OAuth2 application and IMAP permissions to migrate Microsoft 365 mailboxes to Qboxmail.
You can migrate messages from Microsoft 365 mailboxes to Qboxmail using OAuth2 with the client credentials flow, which provides app-only authentication.
This procedure supports both user mailboxes and shared mailboxes in Exchange Online and does not require individual mailbox passwords. To authorize the migration, register an application in Microsoft Entra, configure its IMAP permissions, and grant it access to the source mailboxes.
Before you begin
To complete the setup, you need:
- An administrator account for the Microsoft 365 tenant.
- Permission to grant admin consent to applications in Microsoft Entra.
- Sufficient privileges in Exchange Online to register a service principal and manage mailbox permissions.
- Access to Exchange Online PowerShell for the steps that cannot be completed in the web portal.
Register the application in Microsoft Entra
Sign in to the Microsoft Entra admin center with an account that has the required administrative privileges.
Open Entra ID → App registrations → New registration.
Enter a descriptive name, such as Qboxmail Migration.
Under Supported account types, select Accounts in this organizational directory only (Single tenant) to restrict the migration to your Microsoft 365 tenant.
Leave Redirect URI empty. The client credentials flow does not require a redirect URI.
Select Register.
In Overview, note the Application (client) ID and Directory (tenant) ID.
Do not enable Allow public client flows. The application uses a client secret rather than an interactive OAuth flow based on user credentials.
Add the IMAP permission
In the application you just registered, open API permissions → Add a permission.
Select APIs my organization uses. The label may vary depending on the portal version.
Search for and select Office 365 Exchange Online, not Microsoft Graph.
Select Application permissions, not Delegated permissions.
Select IMAP.AccessAsApp, then Add permissions.
In API permissions, select Grant admin consent for [organization] and confirm.
Verify that IMAP.AccessAsApp appears under Office 365 Exchange Online, with Application as the permission type and admin consent granted.
Do not replace IMAP.AccessAsApp with IMAP.AccessAsUser.All, offline_access, or User.Read: these permissions apply to delegated authentication and do not provide the app-only IMAP access described in this guide. The full_access_as_app permission for EWS is not required for IMAP migration.
Create the client secret
In the application, open Certificates & secrets → Client secrets → New client secret.
Enter a description, such as qboxmail-migration-secret.
Choose a lifetime that covers the initial migration and subsequent incremental synchronizations. For example, you can use 90 days if this option is available and complies with your organization's policies.
Select Add.
Copy the secret's Value immediately: Microsoft will not display the full value again.
Store the secret securely. Do not include it in regular email messages or screenshots.
Copy the secret's Value, not its Secret ID. The ID cannot be used in place of the client secret.
At this point, you should have:
- Application (client) ID.
- Directory (tenant) ID.
- Client secret value.
Find the enterprise application's object ID
Exchange Online requires the object ID of the enterprise application, which is the service principal. This is different from the object ID shown under App registrations.
In Microsoft Entra, open Entra ID → Enterprise applications → All applications.
Find the application by its name or application ID.
Open Overview and note the Object ID.
Verify that the Application ID matches the Application (client) ID you noted during registration.
Keep the enterprise application's object ID as well: you will need it to register the service principal in Exchange Online.
Register the service principal in Exchange Online
This procedure registers the application you already created in Microsoft Entra with Exchange Online. It does not create a second Entra application.
Run the commands using an administrator account with the required Exchange Online permissions.
Connect to Exchange Online PowerShell
On a Windows computer, open PowerShell. If the Exchange Online module is not installed, run:
Install-Module ExchangeOnlineManagement -Scope CurrentUserImport the module and connect using an authorized administrator account:
Import-Module ExchangeOnlineManagement
Connect-ExchangeOnline -UserPrincipalName admin@example.comReplace admin@example.com with your administrator account and complete multifactor authentication if prompted.
Check and register the service principal
Check whether the service principal already exists. Replace YOUR_APPLICATION_CLIENT_ID with the Application (client) ID:
Get-ServicePrincipal | Where-Object { $_.AppId -eq "YOUR_APPLICATION_CLIENT_ID" } | Format-List Identity,AppId,ObjectId,DisplayNameIf a matching service principal already exists, use it and continue with granting mailbox permissions.
If the command completed without errors and did not return a matching service principal, register it:
New-ServicePrincipal -AppId "YOUR_APPLICATION_CLIENT_ID" -ObjectId "YOUR_ENTERPRISE_APPLICATION_OBJECT_ID" -DisplayName "Qboxmail Migration"Replace YOUR_APPLICATION_CLIENT_ID with the Application (client) ID and YOUR_ENTERPRISE_APPLICATION_OBJECT_ID with the enterprise application's object ID.
Run the verification command from the first step again to confirm that registration was successful.
The -ObjectId value must come from Enterprise applications, not App registrations. An incorrect object ID can prevent IMAP authentication. Do not create a duplicate if the service principal already exists.
Grant access to mailboxes
Exchange Online requires FullAccess permission on each source mailbox. You can grant it to all user and shared mailboxes currently in the tenant in a single PowerShell operation.
The following procedure authorizes the application to access all user and shared mailboxes in the connected tenant, including mailboxes that may not be part of the migration. Run it only if your organization approves this scope of access.
Permissions are granted to existing mailboxes: they do not automatically apply to mailboxes created later.
Retrieve the service principal registered in Exchange Online. Replace YOUR_APPLICATION_CLIENT_ID with the Application (client) ID:
$SP = Get-ServicePrincipal | Where-Object { $_.AppId -eq "YOUR_APPLICATION_CLIENT_ID" }Before continuing, verify that $SP is not empty and identifies the intended Qboxmail Migration application.
Preview the mailboxes that will receive the permission. This command is read-only:
Get-Mailbox -ResultSize Unlimited -RecipientTypeDetails UserMailbox,SharedMailbox | Select-Object PrimarySmtpAddress,RecipientTypeDetailsAfter reviewing the list and scope of access, grant FullAccess to the mailboxes:
Get-Mailbox -ResultSize Unlimited -RecipientTypeDetails UserMailbox,SharedMailbox |
Add-MailboxPermission -User $SP.Identity -AccessRights FullAccess -Confirm:$falseThe command grants permission separately to each mailbox returned by Get-Mailbox. It does not create a permanent tenant-wide permission.
Review the output and any errors. If permission cannot be assigned to a mailbox, resolve the issue before migrating it. Running the command again may produce a message indicating that a permission already exists.
Verify the result for a sample mailbox and for every mailbox that reported an error. Replace user@example.com with the address you want to check:
Get-MailboxPermission -Identity "user@example.com" -User $SP.Identity | Format-List User,AccessRights,Deny,IsInheritedThe expected result includes:
AccessRights: FullAccess.Deny: False.IsInherited: False.
No Microsoft 365 mailbox passwords are required, including for shared mailboxes.
Verify that IMAP is enabled
Check that IMAP is enabled on all user and shared mailboxes included in the migration.
In Exchange Online PowerShell, replace user@example.com with the mailbox address and run:
Get-CASMailbox -Identity "user@example.com" | Format-List PrimarySmtpAddress,ImapEnabledThe expected value is ImapEnabled: True. Repeat this check for each mailbox you want to migrate.
Alternatively, check the setting in the portal:
Sign in to the Exchange admin center.
Open Recipients → Mailboxes and select the mailbox you want to check.
Check Email apps or Manage email apps settings. The labels may vary depending on the interface version.
If IMAP is disabled, the tenant administrator must decide whether to enable it for the migration in accordance with the organization's security policies.
Provide the details to Technical Support
Once setup is complete, provide Qboxmail Technical Support with:
- Directory (tenant) ID.
- Application (client) ID.
- Client secret value, using the secure method agreed with Support.
- Enterprise application's object ID, to help verify registration in Exchange Online.
- The complete list of source mailbox addresses to migrate, including shared mailboxes.
- Confirmation that admin consent for
IMAP.AccessAsApp, service principal registration in Exchange Online, FullAccess permission on the relevant mailboxes, and IMAP enablement are all complete.
Do not provide individual Microsoft 365 mailbox passwords: the client credentials flow does not use them. Do not send access tokens or secrets through unprotected messages.
Qboxmail can use the same application's access token for multiple authorized mailboxes in the same Microsoft 365 tenant, even if they use different email domains. Exchange Online continues to enforce permissions on each mailbox, even when permissions are granted in a single operation.
Migrate and switch to Qboxmail
Qboxmail Support verifies the application configuration and IMAP OAuth2 authentication, then starts the initial message synchronization.
Keep the Microsoft 365 mailboxes and application credentials available until migration checks and any final synchronization are complete.
Coordinate MX record changes with Qboxmail Support after the initial synchronization, following the agreed migration plan.
Qboxmail can run a final incremental synchronization to copy messages received or modified during the transition.
Configure any features not transferred through IMAP separately, if needed. The migration transfers messages and supported IMAP metadata, but does not automatically recreate Microsoft 365 shared mailbox delegation, calendars, contacts, or other non-IMAP features.
Permissions granted in Exchange Online can take time to propagate. If authentication fails immediately after a change, allow time for propagation and try again before recreating the application or credentials.
Troubleshooting
| Problem | What to check |
|---|---|
| The token request fails | Check the tenant ID, application ID, client secret value and expiration, and admin consent. |
The token does not contain the IMAP.AccessAsApp role | Check the Office 365 Exchange Online application permission and admin consent. Generate a new token after making changes. |
NO AUTHENTICATE failed | Check the token audience and role, service principal registration in Exchange Online, the object ID used, mailbox permissions, and IMAP availability. |
User is authenticated but not connected | Check FullAccess on the individual mailbox, the ImapEnabled value, the mailbox's actual status, and any permission propagation delays. |
| One mailbox works but another does not | Check the permissions and IMAP settings of the affected mailbox, including shared mailboxes. |
These errors provide diagnostic clues, but do not always identify a single cause. Qboxmail Support may ask for the results of the verification commands in this guide.
Never include a complete OAuth access token or client secret in logs shared for troubleshooting.
Remove temporary access
Proceed only after Qboxmail has confirmed that the initial and final synchronizations are complete and you have verified the migrated mailboxes.
Verify that access to Microsoft 365 is no longer needed for the migration.
Revoke or delete the temporary client secret in Microsoft Entra.
Remove temporary FullAccess assignments and the dedicated service principal in Exchange Online if they are no longer needed.
Delete the dedicated application registration if it was created exclusively for this migration and is no longer needed.
Revoke any temporary administrator accounts or privileges granted for troubleshooting.
Coordinate these actions with Qboxmail to avoid interrupting a scheduled final synchronization. Follow your organization's retention and audit policies when removing access.