Freeze all incoming messages with Exim.
Doug Ledbetter::Technology::Exim - Freeze all incoming messages.
At my place of employment, we have a development environment which closely mirrors our production environment. We have one application that we manage which sends out several thousand emails each month. In order to test this application in our development environment, we usually have to pare down the list of emails to just a few internal addresses. This isn't a sufficient test in certain circumstances so I was asked to come up with a way that thousands of emails could be sent by the application during testing but prevent them from actually being delivered.
We use Exim version 4.63 for mail on our Linux boxes. After doing some research, it seemed the best way to handle this was to automatically freeze all messages coming into our development environment in the Exim queue and then I could just delete all messages in the queue once a day.
The method I chose to freeze all incoming messages was to use an Exim system filter. The system filter contains only the following:
Note: You must have the "# Exim filter" line at the top of your system filter file.
You can store the above Exim system filter anywhere, but I chose to put it in the same location as my exim.conf file (/etc/exim/). I named mine "exim.filter" but any name will do.
Next, you need to modify your exim.conf file to let Exim know that you have a system filter and where it is. To do so, add the following directives to your exim.conf file (be sure to specify the correct path and file name for your system):
Lastly, you need to deal with all the frozen messages that will be piling up in your Exim queue. To delete all the frozen messages in the queue once a day, I set up a cron job like this:
The above will run every morning at 1:05am and delete any messages in the Exim mail queue. Alternatively you can set a timeout for frozen messages in your Exim configuration file (exim.conf):
timeout_frozen_after = 2d
The above instructs Exim to delete messages that have been frozen in the queue for two days.
Important Note: If you have the "ignore_bounce_errors_after" directive in your exim.conf file, you are in danger of actually delivering or bouncing the frozen messages after the prescribed time period. You should disable that directive if it exists in your exim.conf file. To disable it, just place a hash symbol at the beginning of the line like this:
#ignore_bounce_errors_after = 2d
Finally, to notify the Exim process that you have changed the configuration, you should send the process a SIGHUP or just restart Exim.