I have been plagued with a situation which has yielded no elegant solutions, from any support avenues. I have a domain, the email accounts on this domain are hosted on both Office365 and a cPanel VPS. The VPS is set up as a "smarthost". My MX record points to Office 365, if no matching account is found, the email will be directed to my VPS. If no matching account is found on the VPS, the email message delivery will fail. This all works as expected.
My issue arises if I send an email from the VPS server to the domain which is shared between Office 365 and the VPS, my VPS assumes this is a local email account and delivery fails.
This has been my stop gap solution, added to my Exim configuration in the prerouters section:
office365exchangeForward:
driver = manualroute
condition = ${lookup{$local_part@$domain}lsearch{/home/ben/etc/exim_office365hostedaddresses} {yes}{no}}
transport = remote_smtp
route_list = * bensdomain-com.mail.protection.outlook.com
This subsection checks the recipient address against manually maintained file. If a match exists, the message is forwarded off the VPS back to Office 365 for delivery. This works effectively, but whenever a new alias/group/address is added on the Office 365 side, this file must be manually updated.
Can anyone offer any insight as to how I can accomplish a solution to this split hosting email delivery, without the manual maintenance step?