Server-relief

Copy Sent and Received Email in Exim with cPanel/WHM

Dec
08

For this article, I will be showing you how to create an Exim Filter rule that will allow you to copy all sent and received Email on a certain Email account, to another Email account without the original account being alerted (Blind Carbon Copy – BCC) on a cPanel/WHM server.

 

The server used in this example is a CentOS 6 box with Apache and cPanel (Although the method should be the same on CentOS 5 or any RedHat derivative).

 

Step 1.) Access your server VIA SSH:

kazu@kazu-box:~$ ssh kazu@kazuserver.com
Press { Enter }
Enter your Password
Press { Enter }

 

Step 2.) After SSH’ing in, we need to make a copy of the current Exim filter file to make a backup, as well as have a new one for our editing purposes. I named my new one just “cpanel_exim_system_filter2”, but you can name this whatever you want as long as you remember what you named it!:

[kazu@@kazuserver.com] ~ >> cp /etc/cpanel_exim_system_filter /etc/cpanel_exim_system_filter2

 

Step 3.) Next, open up the newly created “cpanel_exim_system_filter2” file in your favorite text editor (I use Vim in this example):

[kazu@@kazuserver.com] ~ >> vim /etc/cpanel_exim_system_filter2

 

Step 4.) At the END of this file we will be creating our Filters/Rules to BCC ALL Emails Sent/Received to a certain Email account. Make sure you change the “whomever@domain.tld” (who is the sending Email address) as well as the “forward@domain.tld” (which is the Email address that the Email gets forwarded to) to whatever you need them to be:

# Copy all Email sent FROM whomever@domain.tld to forward@domain.tld
if $sender_address: contains "whomever@domain.tld"
then
unseen deliver "forward@domain.tld"
endif
# Copy all Emails sent TO whomever@domain.tld to forward@domain.tld
if $header_to: contains "whomever@domain.tld"
then
unseen deliver "forward@domain.tld"
endif

 

Step 5.) Save and close the file.

 

Step 6.) Next, login to your WHM interface and go to “Service Configuration” >> “Exim Configuration Manager” >> “Filters” and switch it to our new custom filter “/etc/cpanel_exim_system_filter2” and click “Save”.

 

And that is it! You will see cPanel/WHM restart Exim and our new filter/rule will be operational. Now all Emails Sent/Received by our “whomever@domain.tld” will get sent to “forward@domain.tld”