06 Jan 2021

Blocking Accounts From Sending Emails – CPanel/WHM

Is it possible to block certain domains/accounts on my server for sending emails?

It’s possible to block certain domains from sending emails from server. There is an option in Exim configuration on your cPanel server to block domains from sending emails. This can be done by adding those domains into “/etc/blockeddomains” this configuration file.

Here I’m going to explain the steps to block accounts from sending emails. You must have a server with root access to do so.

The steps are explained below:

1. SSH to server as root.
2. Check the file “/etc/blockeddomains” is existing on the server. If it’s not there create one.
3. Add domains in “/etc/blockeddomains” to cut the email sending privilege.

You can use the following commands:

# echo "thedomain.com" > /etc/blockeddomains

Or, open “/etc/blockeddomains” with your favorite text editor and add/append the domain into it.

# vi /etc/blockeddomains
thedomain.com

4. Set correct ownership to “/etc/blockeddomains.”

# chown root.mail /etc/blockeddomains

5. Set correct permission.

# chmod 640 /etc/blockeddomains

6. Then log into the WHM panel and go to “EXIM Configuration Manager.”

WHM –> Service Configuration –> EXIM Configuration Manager –> Advanced Editor
Search for “Add additional configuration setting.” This can be located one by forth of the way of scroll down

Add the following entry:

domainlist blocked_domains = lsearch;/etc/blockeddomains

 

7. Search for “ROUTERSTART” and add the following entry:

reject_domains:

driver = redirect
domains = +blocked_domains
allow_fail
data = :fail: Connection rejected: SPAM source $domain is manually blacklisted.

This should be look like:

Yeah, that’s it!! Next time if you want to block another domain from sending emails, just add that domain into “/etc/blockeddomains” this file,

That’s it!!

08 Feb 2018

Cronjob to delete all emails older than one month

Before starting with the cronjob script, we must know the locations where the emails stored in the server. Then we can go to the steps to remove them  Exactly there are three folders in a cPanel based server for managing received emails.

Those are cur, new, tmp. The main differences between these three are listed below

new : This is the folder where all emails are first received.
cur : Is the folder having emails that are opened/read by mail client.
tmp : Is the folder contains processed emails for delivery purpose.

In most cases these emails in the server cause high disk space usage in the server. We can remove older email by using different ways. Here I’m explaining the steps to remove emails older than one month from the server by the help of cron.

To clear old emails from the server means, remove email related files from cur folder under mails directory and all other mail user directory. There are cur and new directories under the mail folder for cPanel default mail and also the same in each users domain directory. ie /home/username/mail/domain.com/***/cur Here *** represents each mail user folder. (admin/ for [email protected])

Step 1 : Creating an executable file with command to remove emails

For simplicity, create an executable file under anywhere (here I selected the location under root) and place the script to remove older mails.

Here I’m using the find command to find and remove mails which are older than 30 days (-mtime switch for finding mails older than 30 days.

[[email protected]]# touch mailcleaner.sh

Edit the file using your favorite file editor

[[email protected]]# vim mailcleaner.sh

find /home/username/mail/yourdomain.com/*/cur -type f -mtime +30 -exec rm -f {} \;
~
 :wq

Then change that file to an executable one. (ie file permission to 755)

[[email protected]]# chmod 755 /root/mailcleaner.sh

Step 2 : Creating CRON job

Next step is to set the cronjob under root (for setting a cronjob refer this link). Here I’m setting the cron job to run every 1 day of the month.

[[email protected]]# crontab -e
 0 0 1 * * /root/mailcleaner.sh > /dev/null 2>&1
 :wq
[[email protected]]# crontab -l : To list all cronjobs.

In this case the file mailcleaner.sh will execute first day of every month and remove all emails older than 30days.

Thank you.

©2021 Tranzmedia Netvision Limited. All Rights Reserved.
Top