Block direct delivery to addresses

We're all familiar with how Office 365 tenants work--when you spin up a new Office 365 tenant, you get a managed domain (  Then, maybe you configure a hybrid environment, and now your tenant has your domain, as well as your original domain, and a new  The two managed and both have internet-routable MX records:

Now, let's say you're in a hybrid mail scenario and you have begun synchronizing users and have migrated some mailboxes.  When you synchronize mail-enabled user accounts and migrate mailboxes, your users will get stamped with a tenant address.  Since we already know that the managed domains have their own MX hosts configured, that means that you can deliver mail destined a migrated user (who might have a primary SMTP address of using their address (

If you have certain mail flow or business requirements (such as DLP, encryption, or other content filtering that has not yet been configured in Office 365) that force your inbound email to traverse a certain path, you may find that unacceptable.  To prevent email delivery to the namespace directly, you can use the create a transport rule in your Exchange Online Tenant using the following script:

[array]$TenantDomains = (Get-AcceptedDomain | ? { $_.DomainName -like "*" }).Name
New-TransportRule -FromScope NotInOrganization -RecipientDomainIs $TenantDomains -Name "Reject messages to domains" -RejectMessageEnhancedStatusCode 5.7.1 -RejectMessageReasonText "You are not allowed to relay to this user's managed domain name. Please resubmit your message using the recipient's public email address." -StopRuleProcessing $True

The result when you attempt to send mail to an address in that tenant from a mailbox outside the Exchange organization (either on-premises or in-cloud):

You can see that the status code says 5.7.1 (our status code) and has _ETR appended (meaning it was generated by an Exchange Transport Rule).

Comments (1)

  1. turbomcp says:

    good one
    we saw this around 2-3 years ago its amazing nobody else did:)

Skip to main content