cPanel & WHM

How To Connect Your cPanel Server To A SmartHost Relay

Connect cPanel to a SmartHost Relay

A smarthost relay is an external SMTP server that you can connect to your cPanel server. The smarthost will deal with the sending of emails from your cPanel server. Usually, companies that offer smarthosts 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 this guide, we use Exim to relay email messages from a cPanel server.

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
cPanel server smarthost relay

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

cPanel Smarthost Relay Settings

Because we have created our own smarthost, we will need to whitelist our development server’s IP so it can connect to our relay. Our development server is using IP 54.36.0.57 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 and finally, restart Exim.

nano /etc/exim/exim.conf
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 148.251.220.14 so we just add it to the record with the original server IP.

v=spf1 +a +mx +ip4:148.251.220.14 +ip4:54.36.0.57 ~all

To Finish Up

Before we configured our smarthost we sent a test mail to an Outlook address. Here are the email headers showing our development server’s 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 54.36.0.57)
  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 54.36.0.57 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 148.251.220.14)
  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 148.251.220.14 as permitted sender)
  receiver=protection.outlook.com; client-ip=148.251.220.14;
  helo=mail.smarthost.email;
 Received: from mail.smarthost.email (148.251.220.14) 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 simpler than changing Exims sending IP.

Related Articles

Leave a Reply

Your email address will not be published. Required fields are marked *

Back to top button