How to block emails by domain in Exim and WHM

Step 1: Create Exim blacklist file

You will need ROOT SSH access to your server, run the following command to create and open a new file in /etc/blockeddomains:

nano /etc/blockeddomains

Enter a domain name per line in the file and then CTRL + O and press ENTER to save the file.

blockeddomain.com
test.com
spam.com

Note: You can add more domains by following the same command and adding more domains on new lines, then restart Exim (see step 3).

Step 2: Add blacklist to Exim config

You will now need to configure EXIM so that it will pick up your blacklist and process any emails against the list, ignoring any that match the domain name.

  1. In WHM search “EXIM” and click “Exim Configuration Manager”, navigate to the “Advanced Configuration” tab.
  2. Scroll down and find the BIG BLUE button labelled “Add additional configuration setting” and click the button, the button should look like the image below:
  3. two input box’s will appear, in the first one enter “domainlist exim_blacklist” and in the second one enter “lsearch;/etc/blockeddomains”.
  4. Scroll down and find the ROUTERS CONFIGURATION section, the first section labelled “Section: PREROUTERS” add the following into the textarea:# Inserted to block domains access # Local from blacklist: /etc/exim_blacklist reject_domains: driver = redirect # RBL Blacklist incoming hosts domains = +exim_blacklist allow_fail data = :fail: Connection rejected: $domain is manually blacklisted.

Step 3: Save Exim & Restart Exim

Scroll to the bottom and click save which will save all the settings and restart Exim.

TIP: If you edit your blacklist file in future simply search WHM for Exim and click on “Mail Server (Exim)” and click restart.

Leave a Reply

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