How to Block Email From a Specific Address by using Exim ?

While working on a client project that had a mass member email function, I needed a way to test the system exactly as it would run in production. This meant, when it ran, it would send emails to all of the members in the directory instead of a test email address. The only problem was I didn’t want to send test emails out to the thousands of members in the directory.

So I wanted a way have PHP still send the email out as it normally would but have the mail server (EXIM) kill it before it left the server.

Luckily this is very easy to do. With EXIM, you can setup filters that can perform a large number of tasks, like blocking message, or blind copying messages to other email addresses. In this case, I’m going to create a filter to cause an email coming from a specific sender to fail (the email address I use to send the email in PHP).

What you’ll want to do is find your System Filter File for EXIM. In WHM, you can find this file listed in your EXIM Configuration Editor about half way down the page.

Once you’ve located the file, log into SSH and edit the file.

pico /path/to/your/file

Then enter the following filter into the file and save it:

if first_delivery
and ( ("$h_from:" contains "emailtoblock@mydomain.com")
)
then fail
endif

If you’d like a copy of the email sent to you after the message fails
so you can make sure it is correctly formatted, just add one line:

if first_delivery

and ( ("$h_from:" contains "emailtoblock@mydomain.com")
)
then
unseen deliver "youremail@yourdomain.com"
fail
endif

I suggest you read up more about EXIM filtering for more advanced functions.

Where I Learned This: I found the solution the Imthiaz Blog and the Exim Documentation.

Enjoy:)

    0 comments: