Copy Outgoing Email on a cPanel Server with Exim
- Written by Vanessa Vasile
- Published in Hacks, Howto, Mail
- 41 Comments
- Permalink
Note: It is mentioned in the comments that recent versions of cPanel include an Email Archiving feature that stores copies of email on the server for you. If this is what you’re trying to do, this feature is probably the better option. However, if you’re trying to forward copies of outgoing email to other addresses, the instructions in this post are appropriate.
A common request we get is how a user can automatically BCC outgoing email to another address. This is most often requested by law firms that need to be able to retain copies of communication. Forwarding incoming email is easy – there’s already a section in cPanel for it. However, if you want to forward outgoing email there’s a small twist.
First, go to WHM > Exim Configuration Editor, then click “Advanced Editor” at the bottom. Don’t make any changes, just click “save”. This should create a file on the server called /etc/exim.conf.local. From command line as root, you’ll need to edit /etc/exim.conf.local and add some options to the @CONFIG@ and @TRANSPORTSTART@ sections. The end result would look like this (plus any edits you may have already made):
@AUTH@
@BEGINACL@
@CONFIG@
system_filter_directory_transport = local_copy_outgoing
@DIRECTOREND@
@DIRECTORMIDDLE@
@DIRECTORSTART@
@ENDACL@
@RETRYEND@
@RETRYSTART@
@REWRITE@
@ROUTEREND@
@ROUTERSTART@
@TRANSPORTEND@
@TRANSPORTMIDDLE@
@TRANSPORTSTART@
local_copy_outgoing:
driver = appendfile
delivery_date_add
envelope_to_add
return_path_add
group = cpaneleximfilter
user = cpaneleximfilter
mode = 0660
maildir_format = true
create_directory = true
Now, make a copy of the existing system filter file to a custom location, so cPanel updates don’t mess with it:
cp /etc/cpanel_exim_system_filter /etc/cpanel_exim_system_filter_custom
Edit /etc/exim.conf.localopts and change the “systemfilter” option to match our new file:
systemfilter=/etc/cpanel_exim_system_filter_custom
Now, open /etc/cpanel_exim_system_filter_custom and add the following block of code to the end of the file:
if $header_from: contains "@senderdomain.com"
then
unseen deliver "other@emailaddress"
endif
Replace the blue text with the sender domain (or email address) and the email address that outgoing mail should be copied to.
Apply these new settings to the exim.conf and restart:
/scripts/buildeximconf
service exim restart
Now when you send email from the email address or domain specified in the filter file, it will be copied to the other email address.
41 Comments
What will happen when the WHM is upgraded? Will it retain the settings or overwrite it?
As long as you follow the instructions, the settings will remain during updates
In your example, it only copies if it matches a certain “FROM domain”
What if we wanted to base the rule on a user?
I want to copy all outgoing emails, even those sent by PHP’s mail() function without a FROM
so the pseudo-code is :
if ( user = someuser )
then
unseen deliver “other@emailaddress”
endif
Is this possible?
And is it possible to create a “copy all outgoing emails”. So ALL outgoing emails from the servers, even by PHP’s mail(), will be copied ?
Thanks in advance Vanessa.
Roy
Pingback: Copy Outgoing Email on a cPanel Server with Exim | whatever...
Thanks Vanessa.
With this method, I can set the rules for incoming email, too? How I can?
Simply create a forwarder for the address within cPanel or /etc/valiases/$domain
### START OF OUTGOING + INCOMING MAIL FORWARDING ###
### domain tappeddomain.com ###
if first_delivery
and (“$h_to:, $h_cc:” contains “@tappeddomain.com”)
or (“$h_from:” contains “@tappeddomain.com”)
then
unseen deliver “[email protected]”
endif
### END OF OUTGOING + INCOMING MAIL FORWARDING ###
Vanessa,
I just update cPanel from 11.28 into 11.30
and on /etc/exim.conf.localops
systemfilter no longer point to /etc/cpanel_exim_system_filter_custom
instead it go to
systemfilter=/usr/local/cpanel/base/eximacl/antivirusandspam.exim
what should I do?
and I get this message after cPanel update complete:
==================================
cPanel was unable to automatically merge your Exim configuration with the new settings that shipped
with the build you have installed (11.30.4 (build 6)) because you have a custom or broken configuration which
cannot be automatically configured.
Your current acl configuration is not compatible with this version of cPanel.
This version of cPanel has an update that is critical, and must be installed to keep email functional on your system.
To avoid any mail downtime, we have replaced the acl configuration with the default configuration.
A copy of the old configuration has been saved to to /etc/exim.conf.local.1318092123.before_acl_version_8.2
If you wish to preserve the old acl configuration, you need to manually merge your configuration
with the new configuration settings.
I did all the above things but its not happening.
Please help me more
Will this work with BCC? 🙂
Can I send the BCC through another route? All my email is routed through an ESP. I would like to route the BCC directly.
Hi all,
My webhosting company uses SpamAssassin, can someone help me to achieve the same thing “Copy Outgoing Email on a cPanel Server with SpamAssassin”
If it can’t be done is there any other way, because it seems like my hosting company don’t have qualified ppl to help, or I am not getting to them clearly.
Please support.
thanks.
The server we tested this procedure on also uses SpamAssassin, and it worked. Keep in mind that the SpamAssassin implementation on cPanel servers only scans incoming mail – outgoing mail is not affected.
i think /etc/exim.conf.localops is misspelled the correct one is /etc/exim.conf.localopts
Pingback: Using DKIM with Exim and cPanel › Lime VPS
Thanks.. It is working fine ..How to collect the incoming emails send via bcc ? Is it possible .. If so just assist me how to proceed ?
if first_delivery
and (“$h_from:, $h_to:, $h_cc:, $h_bcc:” contains “@345.com”)
or (“$h_from:, $h_to:, $h_cc:, $h_bcc:” contains “@345.com”)
or (“$h_from:, $h_to:, $h_cc:, $h_bcc:” contains “@45345.com”)
or (“$h_from:, $h_to:, $h_cc:, $h_bcc:” contains “@fdghdfh.com”)
or (“$h_from:, $h_to:, $h_cc:, $h_bcc:” contains “@345.com”)
or (“$h_from:, $h_to:, $h_cc:, $h_bcc:” contains “@345.com”)
then
unseen deliver “[email protected]”
I have done this but mails getting stuck in queue and erro msg
LOG: MAIN
cwd=/usr/local/cpanel/whostmgr/docroot 4 args: /usr/sbin/exim -v -M 1SmhbU-0004HM-FH
delivering 1SmhbU-0004HM-FH
LOG: MAIN PANIC
Error in system filter: malformed address “[email protected].” in filter file: domain missing or malformed
Could u please guide
we have our hosting account with hostmonster and we would like to have all incoming and outgoing mails to be bcc to a particular mail id. can anyone help me…
Pingback: Some Fixes | firingdreams
Pingback: How to Easily Monitor Cluster Status | The Server Blog
Pingback: Exim / Cpanel auto bcc all sent emails – catalint.ro
Hello Vanessa,
Excellent work!!.
How can we make this for all the domains in the server. I mean all the incoming and outgoing mails to be copied to a single account. What do you suggest to add instead of “if $header_from: contains “@senderdomain.com””. For specifying all the domains at a single line.
Thanks.
we have hosted multiple domains in server we have already implemented the Copy Outgoing Email on a cPanel Server with Exim filter with one domain so kindly help how to implement with one more domain. and how to mention the additional domain filter for outgoing mails for another domain.
And how to mention this file /etc/exim.conf.localopts for multiple domains
or directly we can mention the custom filter with multiple domains so please provide the information how to implement this.
The post actually goes over this. You add each domain to /etc/cpanel_exim_system_filter_custom in the format listed.
This post is actually not needed any longer. Cpanel has the email archive feature. You can download the archive and preserve both incoming and outgoing email. See https://documentation.cpanel.net/display/ALD/Email+Archiving
Ask your hostmaster to enable the feature for cpanel users.
Thank you for your comment. I’ve updated the post with the link to the documentation, noting that the email archiving feature may not actually be a replacement in some cases. If the intention is to copy email for archiving purposes, yes. However, the post was initially intended for users that want to forward outgoing email to another address, which email archiving does not do.
Dear Vanessa Vasile
I implemented this setting and i have only one issue.
Everything works but when i filter the incoming emails to be unseen delivery to my gmail account, i will receive the email in my gmail but the sender email address is changed to system-filter@servername
(change servername with your server hostname)
But if i check the message source i can see the email address of the original sender.
How to fix it?
regards
Does this happen with other mail providers? Try sending the email to another email address that is not @gmail.com and see if it still happens. Some mail providers will rewrite the sender if it thinks the sender is being spoofed, but I haven’t confirmed nor seen this issue myself.
Dear Vanessa Vasile,
We read above details but we using VPS server how to access root and command line cp /etc/cpanel_exim_system_filter. please help..
You need to use SSH. If you’re not familiar with how to do this, you should contact someone who does. Using root when you’re not familiar with how to even log in as root is probably not a good idea.
nice article
Tought i’m doing it wrong, all i need is a several hours and the mail is forwarded just fine. Thanks, Vanessa!
I can’t edit /etc/cpanel_exim_system_filter_custom
Waring :
root@ns [~]# /etc/cpanel_exim_system_filter_custom
-bash: /etc/cpanel_exim_system_filter_custom: Permission denied
How to do next step
It’s not working because you’re trying to execute the file instead of edit it. You need to use an editor. nano /etc/cpanel_exim_system_filter_custom
Any method where we can do this without WHM? My service provider doesn’t provide access to WHM, just cPanel. So I can’t access the SSH! 🙁
I really need to get a copy of the sent emails!
If you don’t have root access, you cannot edit system files.
hello vanessa
i have godaddy acount but i dont know why i cant login to whm
do you have any idea
Ask GoDaddy?
also really 1 need to get a copy of the sent emails! any tricks with cpanle shared cloud ?
I’m intrigued, why is the extra driver needed when you’re using ‘deliver’?