I’ve not used the address rewrite functionality with Microsoft Exchange Edge servers before but had the requirement from a customer to perform a rewrite for email to specific domains when their mailboxes are hosted in Exchange Online. To do this, we require email to be routed back on-premises to a Microsoft Exchange Edge server, which will then send mail out to the designated recipient. I configured a transport rule that sent email for specific domains through a connector to my on-premises Exchange Edge server and configured the address rewrite rules. However, although mail was routing correctly, it did not configure the rewrite.
I found a good post linked below that helped explain how address rewriting works:
After reading the article I determined that mail routing from Exchange Online was not authoritative and this was why the rewrite was not happening. I configured a new receive connector on the Edge server that set Exchange Online Protection IP addresses as authoritative and this enabled the rewrite to work as expected. The below command is an example of what I ran:
New-ReceiveConnector -Name “Exchange Online Protection” -RemoteIPRanges 188.8.131.52-184.108.40.206,220.127.116.11-18.104.22.168,22.214.171.124-126.96.36.199,188.8.131.52-184.108.40.206,220.127.116.11-18.104.22.168,22.214.171.124-126.96.36.199,188.8.131.52-184.108.40.206,220.127.116.11-18.104.22.168,22.214.171.124-126.96.36.199,188.8.131.52-184.108.40.206,220.127.116.11-18.104.22.168,22.214.171.124-126.96.36.199,188.8.131.52-184.108.40.206,220.127.116.11-18.104.22.168,22.214.171.124-126.96.36.199,188.8.131.52-184.108.40.206,220.127.116.11-18.104.22.168,22.214.171.124-126.96.36.199,188.8.131.52-184.108.40.206,220.127.116.11-18.104.22.168 -Usage Custom -AuthMechanism Tls -PermissionGroups AnonymousUsers, ExchangeServers, Partners -Bindings 0.0.0.0:25
Get-ReceiveConnector *Exchange* | Set-ReceiveConnector -AuthMechanism ExternalAuthoritative, Tls -RequireTls:$true -TlsDomainCapabilities mail.protection.outlook.com:AcceptOorgProtocol -Fqdn “mail.domain.co.uk” -TlsCertificateName “<I>CN=GlobalSign Organization Validation CA – SHA256 – G2, O=GlobalSign nv-sa, C=BE<S>CN=hybrid.domain.co.uk, O=Company L=Town, S=County, C=GB”
Note I have changed the FQDN and TlsCertificateName parameters to exclude the company I was working for, but this should help anyone else in a similar situation I was in. There is also the risk with this method that EOP IP addresses may change, I would recommend adding yourself to the RSS feed that can be found on the Office 365 IP addresses page.