The Community Forums

Interact with an entire community of cPanel & WHM users!
  1. This site uses cookies. By continuing to use this site, you are agreeing to our use of cookies. Learn More.

How To: Setup SMTP Relay and Follow Max Hourly Mail Limits

Discussion in 'E-mail Discussions' started by cPMatthewV, May 28, 2015.

  1. cPMatthewV

    cPMatthewV Quality Assurance Analyst
    Staff Member

    Joined:
    Apr 11, 2014
    Messages:
    21
    Likes Received:
    15
    Trophy Points:
    3
    Location:
    Houston, Tx
    cPanel Access Level:
    Root Administrator
    To setup a remote smtp relay with authentication that will adhere to and follow your max hourly mail limits we will make a slight change to this process as in the previous forum article on creating an smtp relay with authentication.

    First login to WHM and then proceed to the following location Home »Service Configuration »Exim Configuration Manager and click the Basic Editor tab.

    From here search for Smarthost Support under the Mail tab. Enter your smart host as follows. Please note the space between the * (asterisk) and hostname. Then hit save.
    Code:
    * my.smarthost.com
    Next go to the Advanced Editor Tab and look for each of the sections below and enter the information below that section into the corresponding boxes in the configuration editor. Make sure to update this information with your smtp server, username and password.

    Section: POSTMAILCOUNT
    The POSTMAILCOUNT section must be used instead of ROUTERSTART if you wish for max hourly mail limits to be followed and used. You must also add the domains = section if you wish for the server to still accept mail for the localdomains and only relaying mail out. Otherwise all email, incoming and outgoing gets relayed.

    Code:
    remoteserver_route:
      driver = manualroute
      transport = remoteserver_relay
      domains = !+local_domains
      route_list = * smtp.server.com
    Section: TRANSPORTSTART
    Code:
    remoteserver_relay:
      driver = smtp
      port = 587
      hosts_require_auth = $host_address
      hosts_require_tls = $host_address
    Section: AUTH
    Code:
    remoteserver_login:
      driver = plaintext
      public_name = LOGIN
      hide client_send = : user@domain.com : password
    If you wish to use DKIM from the Server add the following to each section as well.

    Section: POSTMAILCOUNT
    Code:
    smarthost_dkim:
      driver = manualroute
      domains = !+local_domains
      require_files = "+/var/cpanel/domain_keys/private/${sender_address_domain}"
      transport = remote_smtp_smart_dkim
      route_list = * smtp.domain.com
    Section: TRANSPORTSTART
    Code:
    remote_smtp_smart_dkim:
      driver = smtp
      hosts_require_tls = *
      interface = ${if exists {/etc/mailips}{${lookup{$sender_address_domain}lsearch*{/etc/mailips}{$value}{}}}{}}
      helo_data = ${if exists {/etc/mailhelo}{${lookup{$sender_address_domain}lsearch*{/etc/mailhelo}{$value}{$primary_hostname}}}{$primary_hostname}}
      dkim_domain = $sender_address_domain
      dkim_selector = default
      dkim_private_key = "/var/cpanel/domain_keys/private/${dkim_domain}"
      dkim_canon = relaxed
    
    Once you have finished adding the above to all the appropriate sections, simply scroll to the bottom of the page and click save. It will automatically apply the settings and restart exim. Now anytime you send mail out it will be routed out through the remote smtp relay and will continue to follow your max hourly mail limits.

    If you have any issues or questions with this feel free to open a ticket.
     
    #1 cPMatthewV, May 28, 2015
    Last edited: Oct 21, 2015
    Tarl and Infopro like this.
  2. LostNerd

    LostNerd Well-Known Member

    Joined:
    Mar 12, 2014
    Messages:
    258
    Likes Received:
    11
    Trophy Points:
    18
    Location:
    Hastings, East Sussex, UK
    cPanel Access Level:
    Root Administrator
    Twitter:
    Great tutorial.

    Scenario: You have multiple cPanel accounts... Some domains use the remote Office365 Exchange platform, others use the cPanel email accounts... Do you have a way to set up a relay per account?

    The reason I ask is that I would like cPanel/SpamAssassin to be able to scan an email before relaying it further, whilst holding the capability of using a local mail exchange OR a remote mail exchanger.

    Peter
     
  3. cPMatthewV

    cPMatthewV Quality Assurance Analyst
    Staff Member

    Joined:
    Apr 11, 2014
    Messages:
    21
    Likes Received:
    15
    Trophy Points:
    3
    Location:
    Houston, Tx
    cPanel Access Level:
    Root Administrator
    Hi,

    The following article may be of some help with this. This will allow you to set up a relay on a per domain basis. Unfortunately there is no way to do this per cPanel account level however.

    In summary it looks like you need to add the following to POSTMAILCOUNT if you plan to only relay for specific domains.
    Code:
    remoteserver_route:
      driver = manualroute
      transport = remoteserver_relay
      domains = !"+local_domains +smart_hosts"
      condition = "${if eq{${lookup{$sender_address_domain}partial-lsearch{/etc/staticroutes}{$value}}}{}{false}{true}}"
      route_list = !+local_domains "${lookup{$sender_address_domain}partial-lsearch{/etc/staticroutes}}"
    
    You would also want to add the following to the CONFIG section by clicking "Add additional configuration setting" and then using the following.
    Code:
    hostlist smart_hosts = lsearch;/etc/smarthosts
    
    Then add your smart host to /etc/smarthosts
    Code:
    smtp.domain.com
    
    Followed by the domains you wish to relay here. You can also specify wildcards.
    Code:
    mydomain.com: smtp.domain.com
    *.mydomain.com: smtp.domain.com
    
    This will only relay the domains in that file and everything else would send out through the server. You can also use this to relay certain domains through different servers.

    I have tested this and it seems to work fine. The forum article linked above looks to have additional configuration options which may be used but I do not see as being required.
     
    #3 cPMatthewV, May 28, 2015
    Last edited: Jun 30, 2015
    LostNerd likes this.
  4. Kurieuo

    Kurieuo Well-Known Member

    Joined:
    Dec 13, 2002
    Messages:
    98
    Likes Received:
    0
    Trophy Points:
    6
    Location:
    Australia
    For the Smarthost Support under the Mail tab, you need to set it back to "default" to get delivery to domains not found in /etc/staticroutes via your server.

    Otherwise, after much reading, and thanks to this article and the links forum posts, I've got the smart host finally setup to work per domain with Mandrill. Tested and working, and now to monitor Exim's mail logs just to be sure.

    Thank you!
     
    #4 Kurieuo, Sep 14, 2015
    Last edited: Sep 14, 2015
  5. akbardotinfo

    akbardotinfo Member

    Joined:
    Jan 3, 2005
    Messages:
    8
    Likes Received:
    0
    Trophy Points:
    1
    Hi Mat,

    I've try this but it doesnt work, this is the log on the server:
    I've already hit the MAIL tab and the smarthost on default values.


    2015-09-16 16:03:32 cwd=/var/spool/exim 3 args: /usr/sbin/exim -Mc 1Zc8cg-00087o-Su
    2015-09-16 17:09:12 failed to expand condition "${if and{{bool_lax{NULL}}{bool_lax{${if eq{${lookup{$sender_address_domain}partial-lsearch{/etc/staticroutes}{$value}}}{}{false}{true}}}}}}" for remoteserver_route router: failed to open /etc/staticroutes for linear search: No such file or directory inside "and{...}" condition



    cat /etc/smarthosts
    domain.co.id: 202.1*4.1*.2

    but none email relay to the server that I define on the smarthost

    Thank you!

     
    #5 akbardotinfo, Sep 16, 2015
    Last edited: Sep 16, 2015
  6. LostNerd

    LostNerd Well-Known Member

    Joined:
    Mar 12, 2014
    Messages:
    258
    Likes Received:
    11
    Trophy Points:
    18
    Location:
    Hastings, East Sussex, UK
    cPanel Access Level:
    Root Administrator
    Twitter:
    I believe they are deferred until said limits are lifted. (The next 200 would be sent after the hour)
     
Loading...

Share This Page