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.

Howto: redirect a copy of your emails to another server while saving it locally

Discussion in 'E-mail Discussions' started by consultorpc, Aug 10, 2011.

  1. consultorpc

    consultorpc Well-Known Member
    PartnerNOC

    Joined:
    Jun 18, 2003
    Messages:
    51
    Likes Received:
    0
    Trophy Points:
    6
    Hello,

    We are posting this here in case it helps someone. With a few config changes on exim you can redirect your messages to an external server while keeping a copy locally.

    First thing is to add a route for it.

    Go to WHM -> Exim Configuration Editor -> Advanced Editor. Search for "ROUTERS CONFIGURATION" and add the following text on the textarea below it:

    Code:
    smarthost:
    	driver = manualroute
    	domains = yourdomain.com
    	unseen
    	transport = remote_smtp
    	headers_add = X-Custom-Forwarded: true
            condition = ${if match {$h_X-Custom-Forwarded:}{true}{false}{true}}
    	route_data = "aspmx.l.google.com"
    In this case, we are redirecting all message sent to yourdomain.com to google's server. Change it according to your needs.

    After that, you have to create a system filter. Create file /etc/custom_cpanel_exim_system_filter ( by default Cpanel use /etc/cpanel_exim_system_filter but upcp usually overwrites it when a new version is out ) and add this:

    Code:
    if first_delivery
    	and $h_X-Custom-Forwarded contains "true" 
    then
       seen
       finish
    endif
    This filter is necessary to avoid infinite loops in case the other email server is also redirecting back to you.

    Now, go to WHM -> Exim Configuration Editor -> search for filter add edit System Filter File to point to /etc/custom_cpanel_exim_system_filter.

    Save the new configuration and you are done.

    Note: watch exim log to make sure everything is working fine.

    In case something went wrong, you can always revert things by removing the changes on /etc/exim.conf.local and running /scripts/buildeximconf to build a new configuration. Don't forget to restart exim.

    Hope it helps someone.
     
    #1 consultorpc, Aug 10, 2011
    Last edited: Aug 10, 2011
  2. cPanelTristan

    cPanelTristan Quality Assurance Analyst
    Staff Member

    Joined:
    Oct 2, 2010
    Messages:
    7,623
    Likes Received:
    21
    Trophy Points:
    38
    Location:
    somewhere over the rainbow
    cPanel Access Level:
    Root Administrator
    Is there a reason that the advice is being provided to manually edit /etc/exim.conf.local rather than putting this into WHM > Exim Configuration > Advanced Editor section?
     
  3. consultorpc

    consultorpc Well-Known Member
    PartnerNOC

    Joined:
    Jun 18, 2003
    Messages:
    51
    Likes Received:
    0
    Trophy Points:
    6
    No, just thought it was easier to explain this way rather than saying to edit 5th box on advanced editor, which could make someone insert it at the wrong place.

    After all the result is the same, no?
     
  4. cPanelTristan

    cPanelTristan Quality Assurance Analyst
    Staff Member

    Joined:
    Oct 2, 2010
    Messages:
    7,623
    Likes Received:
    21
    Trophy Points:
    38
    Location:
    somewhere over the rainbow
    cPanel Access Level:
    Root Administrator
    The file /etc/exim.conf.local doesn't exist on my newly formatted machine. It only exists if you've made changes in WHM > Exim Configuration Editor > Advanced Editor in the past, so it isn't the same result for many people as that file will not exist.

    To show the results, here is my machine before I made changes in Advanced Editor:

    Code:
    root@host [/etc]# ls -lah /etc/exim.conf*     
    -rw-r--r-- 1 root root 47K Aug  8 17:10 /etc/exim.conf
    -rw-r--r-- 1 root root 26K Feb 18 09:11 /etc/exim.conf.dist
    -rw-r--r-- 1 root root  95 Aug  3 17:03 /etc/exim.conf.localopts
    -rw-r--r-- 1 root root 30K Feb 18 09:11 /etc/exim.conf.mailman2.dist
    -rw-r--r-- 1 root root 30K Feb 18 09:11 /etc/exim.conf.mailman2.exiscan.dist
    Here is my machine after I added something in Advanced Editor:

    Code:
    root@host [/etc]# ls -lah /etc/exim.conf*
    -rw-r--r-- 1 root root 47K Aug 10 11:22 /etc/exim.conf
    -rw-r--r-- 1 root root 26K Feb 18 09:11 /etc/exim.conf.dist
    -rw-r--r-- 1 root root 227 Aug 10 11:22 /etc/exim.conf.local
    -rw-r--r-- 1 root root  95 Aug  3 17:03 /etc/exim.conf.localopts
    -rw-r--r-- 1 root root 30K Feb 18 09:11 /etc/exim.conf.mailman2.dist
    -rw-r--r-- 1 root root 30K Feb 18 09:11 /etc/exim.conf.mailman2.exiscan.dist
    I would highly suggest advising to use WHM > Exim Configuration Editor > Advanced Editor in your guide, since otherwise you will have most people who do not have that file exist. Feel free to test this on a new machine to see the results similar to mine above.
     
  5. consultorpc

    consultorpc Well-Known Member
    PartnerNOC

    Joined:
    Jun 18, 2003
    Messages:
    51
    Likes Received:
    0
    Trophy Points:
    6
    Ok, i have updated the instructions on the original post.
     
  6. rclemings

    rclemings Member

    Joined:
    Nov 5, 2007
    Messages:
    23
    Likes Received:
    1
    Trophy Points:
    3
    I used this code (#1) to have server1 send all of its mail through server2. However, I quickly found that every message was being sent twice, once by server1 and again by server2. Removing "unseen" from the smarthost block fixed that. Just in case someone else runs into the same issue.
     
    cPanelMichael likes this.
Loading...

Share This Page