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:
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.
- In WHM search “EXIM” and click “Exim Configuration Manager”, navigate to the “Advanced Configuration” tab.
- 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:
- two input box’s will appear, in the first one enter “domainlist exim_blacklist” and in the second one enter “lsearch;/etc/blockeddomains”.
- 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.