cPanel: Setting up a smarthost for specific domains

Have you ever wanted to relay emails destined for only specific recipient domains to a third-party server (smarthost) rather than being delivered directly from your cPanel server?   If the answer is yes, you’ve come to the right place.

These instructions are for a cPanel server (at this time WHM 54) but really would apply in general to any box running Exim.   Of course the WHM-specific fluff would not be applicable in that case and you would have to edit exim.conf manually.

A.  Create a file to hold your static routes

touch /etc/staticroutes

chown root:mail /etc/staticroutes

B.  Log into WHM and make some changes

Log into WHM and then go to Exim Configuration Manager –> Advanced Editor

Find the empty box right under Section: ROUTERSTART and add the following:

driver = manualroute
transport = remote_smtp
route_data = ${lookup{$domain}partial-lsearch{/etc/staticroutes}}

Then click Save down at the bottom and wait for it to save changes and restart Exim.

C.  edit /etc/staticroutes

Add a domain / smarthost mapping


This tells exim to send all outbound mail destined for the domain to (the smarthost) for further delivery.

D.  Make sure the smarthost allows relaying

Make sure the smarthost box allows the relaying of mail without authentication from the cPanel box’s main IP address.   (since the smarthost box could be any MTA, you’ll have to figure out how to do this on your own).

If we can assume that the smarthost is also a cPanel box, then you can just add the main IP address of the cPanel box that you want to relay from into /etc/trustedmailhosts on the cPanel box that you want to relay to (smarthost).


5 comments on cPanel: Setting up a smarthost for specific domains

  1. Hi there

    Great article really informative and the kind of configuration we are looking for.

    In the Static Routes file is there a way to include a wildcard entry? For example all domains send out through by default except domain and

    We have a lot of domains and don’t want to have to add new domains as they are created manually but rather they would send out through the default route unless otherwise stated.

    1. Matt,

      I may have tried that before, but if I have I forget the answer.

      I believe you can simply use a * to denote a default action on all domains not explicitly listed. I _believe_ you should be able to do:


      Be sure you are understanding what I’m writing about. I’m not referring to mail being sent from cPanel using a specific IP bound to the cPanel ethernet interface. I’m specifically talking about cPanel sending out mail to a specific intermediate mailserver (smarthost) that is taking on the role of finally delivery to the recipient domain.

      So the through aren’t IP addresses attached to the cPanel interface, but rather are the IP addresses of servers elsewhere that you want to hand off your mail to so that they can perform the final delivery.

      You may have the correct understanding already, but I just wanted to clarify that for you.

      In my initial example, “” is some domain that my users are sending to (like AOL.COM). For some reason, I might not want my cPanel server to talk to AOL.COM mailservers directly and instead I might want mail destined for AOL.COM to be delivered to (some box I control that will make the direct connection to AOL.COM servers to deliver the mail. sends an email to results in the email from to taking this path:

      myCpanelServer –> –> MX for

      One might also do this if for some reason mailservers are not accepting mail sent from your cPanel server because they blacklisted you. You might try to send outbound to an intermediate server that you control, which then makes the connection to mailservers so that they don’t see your cPanel IP address. (granted, we all know this isn’t a good idea because any big named email provider would figure out what you were doing and block the intermediate server IP as well). But this is just an example.


  2. To be even more clear (which means I will probably make it even more confusing) …


    In that configuration any email sent from your cPanel server to an external domain will be delivered to by default — so better be configured to further deliver that mail to the recipient domain’s mailsystem.

    And any email send to will be delivered to for further processing, and to for further processing.

    In the above scenario, your cPanel server would not be making any outbound connections to any external domains’ mailservers. It would be passing all outbound email to an intermediate server, and those intermediate servers must be configured to send on the mail to the destination domain.

    If you want your cPanel server to send all mail destined for external domains directly to the MXs for those external domains, then do not add the wildcard.


  3. Hi Mike

    Thanks for the reply.
    I believe I had the correct understanding as we have an external smarthost setup at present so all our servers send out through one smarthost.

    However we are wanting to setup a second smarthost and have certain cPanel users (ones that send out alot of mail for example) to send out through the second smarthost. Would the configuration be the same as you described above?


  4. Matt,

    I don’t use a smarthost for all mail, so I can’t give you a definitive answer. The * wildcard entry _should_ be fine, but the only way you will know is to test it yourself.

    Assuming a * wildcard works, my directions should be appropriate. However, your mileage may vary. Sometimes you just have to bite the bullet and test. The worst case scenario is you have mail hosed up for a second until you revert it back. The best case scenario is everything works as planned.


Leave a Reply

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

This site uses Akismet to reduce spam. Learn how your comment data is processed.