Configure Exim to use a Smart Host on CentOS
A Smart Host is an SMTP server that will accept mail from another server and then deliver the mail for that server. For example, server1 is setup to use server2 as a smart host. Anytime someone sends e-mail on server1 it is automatically relayed to the Smarthost regardless of the MX entries for the domain. Server2 then accepts this message, looks up the proper delivery host/IP and attempts to deliver the message to that host. While the Received: headers will reveal the path of the message having bounced through server2, the entire process is seamless for both the sender and the receiver.
To install Exim, you will need to first enable the EPEL repository. SSH to your server and run the following commands:
yum -y install epel-release
Once that has been completed, run the following commands to install Exim.
yum -y install exim
Source Mailserver Config
To configure a smart host, create /etc/exim.conf.local on the source server (server1 in this example) and add the following lines. Be sure to change to the hostname or IP of the smart host server.
@ROUTERSTART@ smart_route: driver = manualroute domains = !+local_domains transport = remote_smtp route_list = * host.name.of.smart.host.server
Assuming this server (server1) is a cPanel server, next run
/scripts/buildeximconf and then
/scripts/restartsrv_exim. If not, simply restart your Exim server using normal init scripts.
Source Mailserver Config (with cPanel)
Log into WHM.
Go into Mail, Exim Configuration, and then search for SmartHost support in Basic Settings.
In the text box put in the following, replacing X.X.X.X with the IP address or the hostname of the SmartHost server:
Smarthost Server Config
Assuming you're installing the yum version of Exim on a CentOS/RHEL server, you'll need to make two configuration changes. The first is to allow the IP of the mailserver to relay through the smarthost. Open the configuration at /etc/exim/exim.conf, find the line referenced below and edit it replacing X.X.X.X with your mailserver IP.
hostlist relay_from_hosts = 127.0.0.1 : x.x.x.x
Second, you'll need to tell Exim not to listen only on the localhost address for incoming mail, which is the default. Again find the configuration line below and add a hash (#) in front of it to comment it out.
local_interfaces = <; 127.0.0.1 ; ::1
Save the modified config file and restart Exim on this server.
That's it; watch the logs for a bit to make sure it's working! The easiest way is to just
tail -f /var/log/exim_mainlog on both servers and then send a message from server1 to a remote host, and watch for the mail to travel out server2!