MX/SMTP Forwarding with Backup

DReade83

Well-Known Member
Oct 20, 2006
196
0
166
Cheshire, UK
Is it possible to setup cPanel so that any email sent to the domain is forwarded on to a specific IP address (with an Exchange Server on the other end), or if the Exchange Server is down, the email is collected and queued on the cPanel server, while cPanel tries to send the queued mail every X minutes and, as soon as the Exchange Server comes online, the mail is automatically delivered?
 

rikgarner

Well-Known Member
Mar 31, 2006
74
1
158
/dev/null
Hi,
Yes, this is perfectly feasible, and we do this with numerous hosted domains, including our own. What you need to do is:

1. Open up port 25 on your firewall, and port-forward to your internal server via NAT. I strongly recommend you use a firewall which sports "service proxies", we use Watchguard Core series firewalls precisely for this reason.

2. If your internal exchange server is on a domain identical to your external cpanel domain, then you need to add an a-record to Cpanel DNS which has an identical name to your internal server, for example: mysbsserver01 -> 195.5.5.5.

3. Set the primary mx record with a low value (5?) to be mysbsserver01.mydomain.com. (Dont forget the trailing . otherwise it wont work!).

4. SSH onto the server, cd to /etc and vi localdomains. You need to remove the domain you just changed the MX for, and while still in /etc, vi remotedomains and add the domain you just removed from localdomains, otherwise anyone else relaying through your server will get a "mailbox not found" error, or worse, they will build up in a pop-box you are not collecting.

This will have mail going into your exchange server via SMTP. Now, to set Cpanel up to secondary, you need to:

5. In /etc vi secondarymx, and add in your domain name. The file may not exist, but thats normal on some servers.

It *may* be nescessary to tweak your exim.conf to make exim look at the secondaryMX file, to be sure, take a look at exim.conf and make sure it shows the following:

domainlist local_domains = lsearch;/etc/localdomains

domainlist relay_domains = lsearch;/etc/localdomains : \
lsearch;/etc/secondarymx
hostlist relay_hosts = lsearch;/etc/relayhosts : \
localhost

Then all you need to do is head back to DNS config, add a secondary MX with a weighting higher than the first one (10?) which points to the IP Exim is running on.

Sorted!

Rich
 

rikgarner

Well-Known Member
Mar 31, 2006
74
1
158
/dev/null
No worries ;)

Just in case your not aware of it, http://www.dnsreport.com is a fantastic way of checking if you got your DNS settings right :cool:

Rich
 

DReade83

Well-Known Member
Oct 20, 2006
196
0
166
Cheshire, UK
One thing, how do you tell cPanel how many times to check to see if the remote server is active? Does it ping the server every few seconds or minutes to see if it's online?
 

rikgarner

Well-Known Member
Mar 31, 2006
74
1
158
/dev/null
AFAIK, Exim will follow its normal message-delivery retry periods, listed in exim.conf.


Rich
 

DReade83

Well-Known Member
Oct 20, 2006
196
0
166
Cheshire, UK
Well, it worked. Thanks Rich. You've just saved me £150/annum in SMTP Backup charges with Zen! :D

Exim appears to try sending at 5 sec, 10 sec, 30 sec, 1 min intervals and so on, which is great.
 

rikgarner

Well-Known Member
Mar 31, 2006
74
1
158
/dev/null
DReade83 said:
You've just saved me £150/annum in SMTP Backup charges with Zen! :D
Oops! We're a Zen partner! ;)

I can't fault their services, but there is nothing better than being able to do it yourself ;)

Rich