Introduction
If you want or need to set up your mail server to send all outgoing mail to a specific server that will handle the delivery to the recipients, you need to set up an SMTP relay or smarthost.
Prerequisites
- You need to know the hostname of the SMTP server which is going to relay the mail for your mail server. In this case, it's
relay.stacksmtp.com
. - This article assumes that no authentication is necessary on the SMTP relay server.
- This article is written for cPanel with Exim.
- You need to have the login details for WHM ready.
Step 1: Login on WHM
Go to https://x.x.x.x:2087
(replace x.x.x.x
with the IP address of your server).
Step 2: Add SPF include host
Within WHM, navigate to: Main > Service Configuration > Exim Configuration Editor
In the Basic Editor, search for “SPF include hosts for all domains on this system” and change the setting from “None” to:
_spf.stacksmtp.com
Click on “Save” at the bottom.
Step 3: Configure the MTA
On the same page (Exim Configuration Editor
), click on the Advanced Editor button and search for Section: AUTH
, then add the following:
stacksmtp_login: driver = plaintext public_name = LOGIN client_send = : user : password
Step 4: Section: ROUTERSTART
On the same page, search for Section: ROUTERSTART
and add the following:
smart_route: driver = manualroute domains = ! +local_domains transport = auth_relay route_list = * relay.stacksmtp.com::587 no_more
Step 5: Section: TRANSPORTSTART
On the same page, search for Section: TRANSPORTSTART
and add the following:
auth_relay: driver = smtp port = 587 hosts_require_auth = $host_address headers_add = X-AuthUser: ${if match {$authenticated_id}{.*@.*}{$authenticated_id} \ {${if match {$authenticated_id}{.+}{$authenticated_id@$primary_hostname}{$authenticated_id}}}} dkim_domain = ${lookup{$sender_address_domain}lsearch,ret=key{/etc/localdomains}} dkim_selector = default dkim_canon = relaxed dkim_private_key = "/var/cpanel/domain_keys/private/${dkim_domain}"
Step 6: Save Changes
Click the Save button at the bottom of the page to apply the changes and restart the mail server.
Conclusion
Congratulations, you have successfully configured an SMTP relay for your mail server on cPanel/WHM with Exim.