Exim selective copying/bcc’ing of mail based on sender and recipient

If you’re unfortunate enough to be using Exim, and you need to configure the server to selectively bcc some emails (e.g. emails going to a specific recipient need bcc’ing to another address for archiving/compliance purposes) then the following may be useful :

1. Edit /etc/exim4/exim4.conf and add near the top the following :

system_filter = /etc/exim4/mail.filter
system_filter_user = Debian-exim

and restart Exim.

2. Edit /etc/exim4/mail.filter as per the documentation creating something a bit like :

# Exim filter

logfile /tmp/mail.log
logwrite "$tod_log $h_to $h_from $h_subject "

if $header_x-loop-systemfilter contains 'ok'
    logwrite "Mail loop?"

headers add "X-Loop-SystemFilter: ok"

if $sender_address contains "@test.com" and $h_to contains "destination@example.org" 
    logwrite "$tod_log Mail to: $h_to from: $sender_address subject: $h_subject bcc'ed to bcc_address@example.org"
    unseen deliver bcc_address@example.org

So, mail sent from someone matching @test.com to destination@example.org will be bcc’ed to bcc_address@example.org. Changing destination@example.org to just @example.org would obviously catch everything going to the example.org domain through the server.

2 thoughts on “Exim selective copying/bcc’ing of mail based on sender and recipient”

  1. Can you please help me with one of my problem with exim mail server on cPanel ? I want to change the from field for the mails being forwarded from a particular mail ID. Right now it forwards the emails with Keeping FROM field of original sender.I want to change it to the mail ID from which it is being forwarded.

Leave a Reply

Your email address will not be published. Required fields are marked *