Skip to content

How to block emails by domain in Exim and WHM

If like me you have a serious problem with recurring SPAM and looking to block email addresses by domain name. This sort of SPAM is so ANNOYING because they are just insistent on getting you to reply, but you simply want them to go away!! Well now you can force them to go away forever, with a full domain block. This obviously only works for companies who are sending email from their own domain names instead of generic gmail or hotmail accounts, but its very effective as NO email from blocked domains will ever be delivered to any account on your server, they will not even get as far as being processed and will simply be ignored as soon as they request to deliver an email. I found a guide online but it was really messy and confusing so I thought I would create my own guide detailing how to block emails in WHM / Exim by their domain name. Follow my step by step guide below.

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.

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
    driver = redirect
    # RBL Blacklist incoming hosts
    domains = +exim_blacklist
    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.

Nile Youth

Affordable, full service web hosting packages.