Using Exchange Online as mail gateway for decentralized email domains

In some scenarios it is useful to have a central email server that forwards messages to different email servers. You might for example have a company with different business units, each having an email server of their own. In this post I will show you how to get started with the mail flow using one domain, but with several different email servers in Exchange Online.

Consider the following scenario. Several email servers exists within a company:

  • In USA an on-premises Exchange environment is using addresses
  • In Spain an external hosting provider is delivering an email service based on pop3 using addresses
  • In Poland Exchange Online is used, but with addresses

A new corporate policy states that all users must have an email address of the form Also, a central antispam system must be used. At this point no consolidation of email servers will be done. Exchange Online Protection licenses has been bought by the company.

To take care of the mail flow in Exchange Online we have to create our Office 365 tenant and add the domain to it. We also have to change our DNS and let the MX records for point to Exchange Online. This will give us the following mail flow for a user in for example Poland:

Mail flow

I have a csv file with all users in each location:


For each user we will create a mail enabled user that holds the alias and target email addresses. I will use PowerShell to create these users:

#Import all users
$users = Import-Csv users.csv

#Create a password for all users
$Password = ConvertTo-SecureString 'Pa$$w0rd' -asPlainText -Force

#Create mail-enabled user
ForEach ($user in $users) {
	$Name = $user.Name
	$Email = $user.Alias
	$Target = $user.Email
	New-MailUser -Name $Name -MicrosoftOnlineServicesID $Email -ExternalEmailAddress $Target -Password $Password

Now all emails sent to the addresses will be delivered to the current regional email server. The next step would be to configure each email server to use as from address, and only accept incoming emails from Exchange Online.

/ Andreas


1 thought on “Using Exchange Online as mail gateway for decentralized email domains

  1. Pingback: Conditional mail routing in Exchange Online Protection | Tailspintoys –

Comments are closed.