Archive for April, 2020

Filtering outgoing messages with exim4

April 6th, 2020 No comments

Filtering outgoing messages with exim4

1 Purpose

I use exim4 to deliver system emails to an external address.

My purpose is to send a copy of each email that meets some criteria to another email address. Here is how I did it.

2 Version and configuration

  • Version: Debian Buster – exim4 4.92-8+deb10u3
  • Prerequisite: exim4 installed and working

3 Create a filter

Create a new file in /etc/exim4/system_filter.exim. With this filter, all
emails sent on the machine containing the “empire” or “foundation” in the
subject will be also copied to user@domain.tld.

# Exim filter (this is not case sensitive)
if $header_subject: contains "empire" or
$header_subject: contains "foundation"
   unseen deliver user@domain.tld


  • To redirect instead of sending a copy (ie skip the original recipient), replace unseen with seen.
  • To send a copy of all messages sent on the machine to user@domain.tld, just remove the if condition!

4 Tell exim4 to use the filter

Edit /etc/exim4/exim4.conf.template and search for (beginning section of the file):


After that add:

system_filter = /etc/exim4/system_filter.exim

5 Reload configuration and restart exim4

systemctl restart exim4.service

Note: further modifications to /etc/exim4/system_filter.exim don’t require neither a configuration reload nor an exim4 restart.

Categories: Informatique Tags: .: email .: exim4