Community Forums
Connect with us on LinkedIn
+ Reply to Thread
Results 1 to 5 of 5
  1. #1
    cPanel Partner NOC cPanel Partner NOC Badge
    Join Date
    Jun 2003
    Posts
    51

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

    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.
    Last edited by consultorpc; 08-10-2011 at 09:04 PM.

  2. #2
    cPanel Staff cPanelTristan's Avatar
    Join Date
    Oct 2010
    Location
    somewhere over the rainbow
    Posts
    6,305
    cPanel/Enkompass Access Level

    Root Administrator

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

    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?
    cPResources: Support Options | More Support Options | Forums Search | cPanel.net Site Search | Mailing Lists(Alt) | Docs
    -- Tristan, Forums Technical Analyst, cPanel Tech Support

    Submit a ticket | Check an existing ticket

  3. #3
    cPanel Partner NOC cPanel Partner NOC Badge
    Join Date
    Jun 2003
    Posts
    51

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

    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. #4
    cPanel Staff cPanelTristan's Avatar
    Join Date
    Oct 2010
    Location
    somewhere over the rainbow
    Posts
    6,305
    cPanel/Enkompass Access Level

    Root Administrator

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

    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.
    cPResources: Support Options | More Support Options | Forums Search | cPanel.net Site Search | Mailing Lists(Alt) | Docs
    -- Tristan, Forums Technical Analyst, cPanel Tech Support

    Submit a ticket | Check an existing ticket

  5. #5
    cPanel Partner NOC cPanel Partner NOC Badge
    Join Date
    Jun 2003
    Posts
    51

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

    Ok, i have updated the instructions on the original post.

Similar Threads & Tags
Similar threads

  1. MX Mail Routing Issue when sending emails Locally
    By dotcomtim in forum cPanel and WHM Discussions
    Replies: 4
    Last Post: 07-24-2011, 01:53 PM
  2. Replies: 2
    Last Post: 04-14-2010, 11:38 PM
  3. Saving a copy and forward
    By taproot in forum E-mail Discussions
    Replies: 2
    Last Post: 06-02-2009, 10:05 AM
  4. E-Mail Copy and Redirect
    By Hugo Core in forum cPanel and WHM Discussions
    Replies: 1
    Last Post: 12-03-2006, 10:37 AM
  5. HowTo: Copy cPanel Packages from Server to Server
    By comcage in forum cPanel and WHM Discussions
    Replies: 5
    Last Post: 04-10-2004, 02:42 PM
Linkedin       Facebook       Twitter       RSS       Flickr       YouTube