How to Enable Auto Delete Spam for all accounts ?

jayharland

Active Member
Apr 18, 2014
30
1
8
cPanel Access Level
Website Owner
Well one way to do it would be to set up filters that discard emails they catch (such as spam) but that's not recommended. Another way would be to tell Spamassassin to discard spam emails it catches but that's not recommended either. You could create a [email protected] email and redirect everything there at least until you get the filters/settings configured a way you like them. That way you don't risk auto-deleting legit emails flagged as spam.

I'm no pro but I've been fighting spam on my server for some time now using spamassassin and account level filters. We redirect everything to a spam vault and keep it around in case we need to search it for possible false positives.
 

cPanelMichael

Administrator
Staff member
Apr 11, 2011
47,910
2,213
363
Hello :)

You may want to consider utilizing a global filter for Exim. The global filter file is located at:

Code:
/etc/cpanel_exim_system_filter
You can copy this file to a new file and configure Exim to use the custom filter file via the following option under the "Filters" tab in "WHM Home » Service Configuration » Exim Configuration Manager":

"System Filter File"

Thank you.
 

renatoandrade

Member
Feb 20, 2014
21
2
3
cPanel Access Level
Root Administrator
Hello after a long time I found out how to auto delete for all accounts, I will share here because maybe some users may have last the same as I passed, below steps:

First you need to create 3 files with content in them, I recommend also create a folder to store the files, in my case I created the folder /spmass and access folder

Code:
mkdir /spmass ; cd /spmass
First create three files with the names and permissions:

Use the nano editor to create the files:
.filter
filter.cache
filter.yaml

Permissions 0644

Below is a step by step:

Then edit each and place the contents as follows:

File .filter :
Code:
nano .filter
Paste content:
Code:
$h_X-Spam-Bar: contains "+++++"+++++++/dev/null

File filter.cache :
Code:
nano filter.cache
Paste content:
Code:
pst0
-Generated Apache SpamAssassin™ Discard Rule
filtername
   /dev/nulldest
saveactionactions
$h_X-Spam-Bar:part
containsmatch
+++++val

File filter.yaml :
Code:
nano filter.yaml
paste content:
Code:
---
filter:
  -
  actions:
  -
  action: save
  dest: /dev/null
  filtername: Generated Apache SpamAssassin™ Discard Rule
  rules:
  -
  match: contains
  opt: or
  part: "$h_X-Spam-Bar:"
  val: +++++

Change permissions:
Code:
chmod -v 0644 filter* ; chmod -v 0644 .filter

Done all the above procedures is only run the following command:
Code:
for user in `ls /var/cpanel/users/` ; do rsync -v /spmass/.filter /home/$user/ ; chown -v $user:$user /home/$user/.filter ; rsync -v /spmass/filter.* /home/$user/.cpanel/ ; chown -v $user:$user /home/$user/.cpanel/filter* ; done

Restart Exim:
Code:
service exim restart
Ready! Now Spam Auto-Delete feature automatically deletes messages enabled! for all domains and existing accounts in cpanel, if you need to do this for future domains created on the server, simply place the command in a cron job.

I hope this helps.
 
Last edited:

cPanelMichael

Administrator
Staff member
Apr 11, 2011
47,910
2,213
363
I am happy to see you were able to find a solution. Thank you for updating us with the outcome.
 

renatoandrade

Member
Feb 20, 2014
21
2
3
cPanel Access Level
Root Administrator
This setting works with the Force Global On option spamassassin, it automatically deletes those spam, greatly decreases the spam rate in inboxes, but I only use this option because I turn off the Box Trapper.