How do I set up Office 365 to have my domain email routed using MX records and not locally?
By default, Office 365 will attempt a local delivery for domains. If a user is not found with the corresponding email address, an NDR is generated. In order to set up coexistence, users that are not found need to be routed outbound using MX records to your on-premises environment.
To set a domain as an internal relay, type the following commands into remote PowerShell and press Enter:
$cred = Get-Credential
$session = New-PSSession -ConfigurationName Microsoft.Exchange -ConnectionUri https://ps.outlook.com/powershell/ -Credential $cred -Authentication Basic -AllowRedirection
Set-AcceptedDomain example.com -DomainType InternalRelay
Make sure to replace example.com with your actual domain name.