How To Block A Domain From Sending Email On cPanel Servers
Update: You can now block a domain from sending mail on cPanel servers from cPanel > Email Account > Restrict Email Usage. Although this feature can be overridden by end users. Using this feature to block an account from sending emails is preferable.
Sometimes you may need to block a domain on your cPanel VPS Server from sending mail. Unfortunately, there is no way via the cPanel GUI to do this. Lowering the user’s email allocation to 0 can help but this means mail will fill up the mail queue adding extra load to the server and in extreme cases could bring the server down. To block a domain from sending email you can modify the Exim configuration.
Follow this guide to block a single domain or multiple domains from sending email. This includes mail from webmail, SMTP. The user will not be able to send any email until you remove the domain name from the block list. An error message will be displayed to the user.
Create An Exim Block List
Issue the below command to create a blocklist file. This is where banned domain names will be placed and Exim will reference this file.
touch /etc/blockeddomains;chown root:mail/etc/blockeddomains;chmod 640 /etc/blockeddomains
And, Inside the file add the domains you want to ban from sending mail.
echo "domain.com" >> /etc/blockeddomains
echo "domain1.com >> /etc/blockeddomains
Update Exim Configuration
In WHM > Service Configuration > Exim Configuration Manager > Advanced Editor location the following line It’s located at the top under Section:CONFIG
domainlist blocked_domains
In the box to the right of this section, modify the text so it only reads the following line. If there is existing text in this box, remove it and replace it with;
lsearch;/etc/blockeddomains
However, If this section is missing, just add it using the “add section” button. Next, under the ROUTERSTART section add the following code;
reject_domains:
driver = redirect
domains = +blocked_domains
allow_fail
data = :fail: Connection rejected: An administrator has banned $domain from sending mail. Contact support.
Next, restart Exim using systemctl restart exim. The domain will now be blocked from sending email, from their account until you remove the domain name from the /etc/banneddomains file. This only works when a user authenticates using an email account. This method does not stop spam from spam mailing scripts. If these types of scripts are located on your server they should be removed.