cPanel

Shell script to clear the mails in “Default Address” on cPanel Server

Shine Servers

If you are trying to clear the Default (Catch-All) address on your cPanel accounts, you can use the following script. Just place it inside a file named clear.sh on the server, provide executable permission and run it.

vi clear.sh
Enter the following code, save and exit.
#!/bin/sh
for i in $(ls /var/cpanel/users)
do
 rm -rf /home/$i/mail/cur/*
 rm -rf /home/$i/mail/new/*
 rm -f /home/$i/mail/maildirsize
done

Now execute using the following command.

./clear.sh

OR

Navigate to  WHM > Tweak Settings >> Initial default/catch-all forwarder destination.

Forwarding destination for a new account’s catch-all/default address. (Users may modify this value via the Default Address interface in cPanel.)

“fail” rejects the message and notifies the remote SMTP server; this is usually the best choice if you are getting mail attacks.

“blackhole” accepts and processes the message but then silently discards it; this avoids notifying the remote SMTP server but violates SMTP RFC 5321 and generally should not be used.

If you set this to “Fail”, then emails sent to non-existing email accounts on the domain will be bounced back to the sender rather than try to deliver to the user’s default email account. This will only apply to new accounts. Any previously existing accounts will need to have this changed in /etc/valiases from the following.

*: username

To the following:

*: :fail: No Such User Here

Make sure to backup your valiases file before modifying.

cp -rp /etc/valiases /etc/valiases.bakup

Now run the following.

for i in `ls /var/cpanel/users/`;do replace "*: $i" "*: :fail: No Such User Here" -- /etc/valiases/*;done

Done!!!

Tags:

Leave a Reply

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

Time limit is exhausted. Please reload CAPTCHA.

Back to top