I am in the process of revisiting a question I have been attempting to solve for probably way too long; A question with regard to utilizing Office365 Exchange in combination with cPanel Exim to distribute domain emails between the two servers.
The MX records for my domain point to my Office365 Exchange account. At this first stop, I have exchange email boxes, distribution groups, etc, all working as expected. My cPanel server is set up as a smarthost. Any emails which are not slated for an address on the exchange server will then be directed to the smarthost, on which the domain is also correlated with a cPanel account. This also works perfectly.
What does not work perfectly is when I attempt to send an email to the same domain from within the cPanel server, as the address is being treated as a local account, and is not being relayed out to the world to hit the Office365 exchange server.
My stop gap solution to this is as follows, and is placed in the "Routers" section of my Exim configuration.
This solution works, but requires manual intervention, which leads me to believe an easier way to accomplish the same thing has to exist. I presently utilize a powershell script to pull all email addresses from Office365, which then updates the file from which Exim checks, and in turn utilizes the above manual route. The problem being this file can become out of sync when addresses are modified on the Exchange Account.
Does anyone have any suggestions of how to simplify this mailflow, and eliminate the manual update of the file holding all remotely hosted email addresses for the domain?
I apologize in advance if this question seems somewhat convoluted.
Thank you.
Edit: I should also mention, this solution should work for email addresses associated with multiple domains and subdomains.
The MX records for my domain point to my Office365 Exchange account. At this first stop, I have exchange email boxes, distribution groups, etc, all working as expected. My cPanel server is set up as a smarthost. Any emails which are not slated for an address on the exchange server will then be directed to the smarthost, on which the domain is also correlated with a cPanel account. This also works perfectly.
What does not work perfectly is when I attempt to send an email to the same domain from within the cPanel server, as the address is being treated as a local account, and is not being relayed out to the world to hit the Office365 exchange server.
My stop gap solution to this is as follows, and is placed in the "Routers" section of my Exim configuration.
office365exchangeForward:
driver = manualroute
condition = ${lookup{[email protected]$domain}lsearch{/home/benjam1nk/etc/exim_office365hostedaddresses} {yes}{no}}
transport = remote_smtp
route_list = * mydomain-com.mail.protection.outlook.com
This solution works, but requires manual intervention, which leads me to believe an easier way to accomplish the same thing has to exist. I presently utilize a powershell script to pull all email addresses from Office365, which then updates the file from which Exim checks, and in turn utilizes the above manual route. The problem being this file can become out of sync when addresses are modified on the Exchange Account.
Does anyone have any suggestions of how to simplify this mailflow, and eliminate the manual update of the file holding all remotely hosted email addresses for the domain?
I apologize in advance if this question seems somewhat convoluted.
Thank you.
Edit: I should also mention, this solution should work for email addresses associated with multiple domains and subdomains.
Last edited: