A smarthost relay is an external SMTP server that you can connect to your cPanel server. The smarthost will deal with the sending of email from your cPanel server. Usually, companies that offer smart hosts pay great attention to the reputation of the mail server. This ensures your emails get to where they should be without falling into junk folders or disappearing altogether.
In a previous article, we set up an Exim mail server and we are now going to use that as a smarthost relay. We’re going to connect it to our development cPanel server and send mail from the development server through the smarthost relay. This guide assumes you have a working SMTP account on the smarthost.
This guide can also be used on none cPanel servers. Just enter the edits in the /etc/exim/exim.conf file on the server you want to route mail to your relay.
Update Exim Configuration
In our development server which is the server we are going to configure to send mail via the relay we first take a backup of the existing Exim configuration in Home > Service Configuration > Exim Configuration Manager > Backup. Now on the advanced tab use CNTR + F to search for “begin authenticators”. You will see a section at the bottom called Section: AUTH. This is where we enter our relay information.
SmartHostRelay_login: driver = plaintext public_name = LOGIN client_send = : Username : Password
Enter your SMTP username and password for the smarthost. Next, we need to tell Exim to send our mail to the relay. This does not affect local mail on the server. Still in the advanced configuration tab search for POSTMAILCOUNT. In the box enter the SMTP relay information. Our SMTP server is mail.smarthost.email
send_via_SmartHostRelay: driver = manualroute domains = !+local_domains transport = remote_smtp route_list = * mail.smarthost.email::25
Smarthost Relay Settings
Because we have created our own smarthost we will need to whitelist our development servers IP so it can connect to our relay. Our development server is using IP 22.214.171.124 so we need to add this to the hostlist relay_from_hosts section
In the smarthost open up the Exim configuration and add the IP to the section
Now restart Exim
systemctl restart exim
Before sending an email, because we have routed mail via the smarthost your SPF record will now be invalid. In WHM navigate to the DNS Zone Manager and update the SPF with the Smarthost relay IP. Our smarthost is using the IP 126.96.36.199 so we just add it to the record with the original server IP.
v=spf1 +a +mx +ip4:188.8.131.52 +ip4:184.108.40.206 ~all
To Finish Up
Before we configured our smarthost we sent a test mail to a hotmail address. Here’s the email headers showing our development servers IP and the email was sent from our server without a relay.
Received: from VI1EUR04HT180.eop-eur04.prod.protection.outlook.com (2603:10a6:206::42) by AS8P189MB1415.EURP189.PROD.OUTLOOK.COM with HTTPS via AM5PR0601CA0077.EURPRD06.PROD.OUTLOOK.COM; Wed, 10 Feb 2021 20:56:52 +0000 Received: from VI1EUR04FT063.eop-eur04.prod.protection.outlook.com (2a01:111:e400:7e0e::43) by VI1EUR04HT180.eop-eur04.prod.protection.outlook.com (2a01:111:e400:7e0e::66) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.3784.11; Wed, 10 Feb 2021 20:56:52 +0000 Authentication-Results: spf=pass (sender IP is 220.127.116.11) smtp.mailfrom=first2host.org; hotmail.co.uk; dkim=pass (signature was verified) header.d=first2host.org;hotmail.co.uk; dmarc=bestguesspass action=none header.from=first2host.org;compauth=pass reason=109 Received-SPF: Pass (protection.outlook.com: domain of first2host.org designates 18.104.22.168 as permitted sender) receiver=protection.outlook.com;
And after we configured our relay we can see email is now being sent from our smarthost with a valid SPF
Received: from AM5EUR02HT105.eop-EUR02.prod.protection.outlook.com (2603:10a6:209:90::22) by AS8P189MB1415.EURP189.PROD.OUTLOOK.COM with HTTPS via AM6P194CA0009.EURP194.PROD.OUTLOOK.COM; Wed, 10 Feb 2021 21:04:55 +0000 Received: from AM5EUR02FT049.eop-EUR02.prod.protection.outlook.com (2a01:111:e400:7e1c::51) by AM5EUR02HT105.eop-EUR02.prod.protection.outlook.com (2a01:111:e400:7e1c::384) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.3846.25; Wed, 10 Feb 2021 21:04:54 +0000 Authentication-Results: spf=pass (sender IP is 22.214.171.124) smtp.mailfrom=first2host.org; hotmail.co.uk; dkim=none (message not signed) header.d=none;hotmail.co.uk; dmarc=bestguesspass action=none header.from=first2host.org;compauth=pass reason=109 Received-SPF: Pass (protection.outlook.com: domain of first2host.org designates 126.96.36.199 as permitted sender) receiver=protection.outlook.com; client-ip=188.8.131.52; helo=mail.smarthost.email; Received: from mail.smarthost.email (184.108.40.206) by AM5EUR02FT049.mail.protection.outlook.com (10.152.9.233) with Microsoft SMTP
Cool, we’ve successfully configured cPanel to route mail via a smarthost. This is a great tool to have if you have an emergency like an IP listed in an RBL that is preventing mail delivery and is much more simpler than changing Exims sending IP.
How was this article?
You might also like
More from cPanel
How To Install Imunify360 cPanel & DirectAdmin ServersImunify360 is a fantastic tool to have in your server toolkit. It's a …