Migrate mails between Office 365 tenants and keep the existing domain

This article explains how to migrate mails between two Office 365 tenants while keeping the same domain name  ie: move a domain from one tenant to another).

The main challenge is that a domain can be attached to only one Office 365 tenant at a time.
Furthermore, detaching a domain from one tenant is long and complex: no mail addresses referencing the domain to be removed can remain.
Detaching the domain takes up to two days and during this time, you cannot reattach it to another tenant.

This article describes step-by-step how to detach and reattach the domain:
Step-by-step detaching and reattaching the domain.

Cloudiway addresses this issue by proposing a transparent approach.

First, it uses the technical domain of the target tenant to migrate the mail from user@company.com to user@tenant2.onmicrosoft.com.
When the migration is complete, Cloudiway ensures that mail routing continues during the period when the domain is being detached from the source and cannot yet be reattached to the new tenant. During this period, no mails are lost and they are delivered transparently to the target.

See how the routing is done.

1. Mailbox migration

Use Cloudiway to migrate your mailboxes from company.com (tenant 1) to tenant2.onmicrosoft.com (tenant 2).
Choose a big bang migration: Cloudiway migration platform is able to do this very quickly and can migrate thousands of users in a limited amount of time.

2. Mail routing

Cloudiway provides a mail routing platform that forwards mails from company.com (your domain) to tenant2.onmicrosoft.com
The transition will be transparent.
When you are ready to detach your domain, switch your MX records and point to Cloudiway mail routing platform.

Note: At the beginning of your migration, decrease the TTL of the MX record to the minimal value, so that there will be no caching issue when you will switch your MX records.

Every incoming mail for user@company.com will be delivered transparently to user@tenant2.onmicrosoft.com
Therefore, even if it takes a few days to detach your domain, mail delivery will be performed transparently and the mails will be delivered to the target mailboxes even if the domain is not attached yet to the target tenant.

3. Domain detach

You’re now ready to activate the target tenant and to detach your domain from the source tenant.
You must first remove all the primary SMTP addresses and aliases that reference your domain company.com.
Here is an example PowerShell script that modifies all mail addresses.

1. Rename users

Get-MsolUser | ForEach { Set-MsolUserPrincipalName -ObjectId $_.ObjectId -NewUserPrincipalName ($_.UserPrincipalName.Split(“@”)[0] + “@THesourcedomain.onmicrosoft.com”) }

Once there are no more accounts that keep a reference to the source domain, Office 365 lets you detach the domain from the tenant ( Admin -> Office365 -> Domains -> Delete a domain )

At this time, the domain is being detached but cannot be reattached yet in the target tenant (because it still “belongs” to the source tenant).
Therefore, your users can start using the target mailboxes but they must use user@tenant2.onmicrosoft.com to login to the target.
If the transition is performed during a weekend, we recommend the users to login temporarily using OWA with the onmicrosoft.com UPN at the target (this will avoid a double Outlook reconfiguration).

2. Wait for the replication delay to expire.

Once the domain is free, you can reattach it to the target tenant.
In the Office 365 admin portal, go to Admin -> Office365 -> Domains -> Add a domain

3. DNS settings

Set the txt verification record.

4. Reassign all your users their primary SMTP address.

Use Cloudiway Identity Management to set the primary SMTP address to their original value, eventually develop a PowerShell script to set all primary SMTP addresses.

5. Change your MX records.

You can now point your MX records to the target Office365 tenant.

Detailed action plan here: Domain migration in details.