** actualized on 13 November, 2017 **
If you want SpamAssassin to work at its best it should be trained to differentiate SPAM and legitimate emails. You can do it either manually with sa-learn or using scripts for automation. Here we will describe on how you can start increasing efficient of SpamAssassin by using our set of scripts which were already tested on our own servers as well on servers of our clients.
A set of scripts to create folders and teach SpamAssassin per user on Directadmin based servers can be found in our GitHub repository. Every single user in our realization has it's own bayes files stored under his/her homedir.
Check it in our GitHub: https://github.com/poralix/directadmin-teach-sa
cd /usr/local/directadmin/scripts/custom/ git clone https://github.com/poralix/directadmin-teach-sa.git cd ./directadmin-teach-sa cp -p ./0teach-sa_cron /etc/cron.d/ cp -p settings.cnf.default settings.cnf
Before running update settings.cnf to fit your needs. For example if you need to change folders' names:
# TEACH SPAM FOLDER TEACH_SPAM_FOLDER="INBOX.teach-isspam"; # TEACH NOT SPAM FOLDER TEACH_HAM_FOLDER="INBOX.teach-isnotspam"; # TO DELETE OR NOT EMAIL AFTER TEACHING SPAM DELETE_TEACH_SPAM_DATA="0"; # TO DELETE OR NOT EMAIL AFTER TEACHING NOT SPAM DELETE_TEACH_HAM_DATA="0"; # TO MARK AS READ OR NOT EMAIL AFTER TEACHING SPAM # DELETE_TEACH_SPAM_DATA SHOULD BE SET TO 0 MARK_AS_READ_TEACH_SPAM_DATA="1"; # TO MARK AS READ OR NOT EMAIL AFTER TEACHING NOT SPAM # DELETE_TEACH_HAM_DATA SHOULD BE SET TO 0 MARK_AS_READ_TEACH_HAM_DATA="1";
cd /usr/local/directadmin/scripts/custom/directadmin-teach-sa ./create_folders.sh --all
create_folders.sh - a script to create teach-isspam and teach-isnotspam folders:
For this we will use Directadmin's hook-script: /usr/local/directadmin/scripts/custom/email_create_post.sh
Copy the sample email_create_post.sh.sample to /usr/local/directadmin/scripts/custom/email_create_post.sh if it does not exist yet:
cp -p /usr/local/directadmin/scripts/custom/email_create_post.sh /usr/local/directadmin/scripts/custom/email_create_post.sh~bak cp email_create_post.sh.sample /usr/local/directadmin/scripts/custom/email_create_post.sh chmod 700 /usr/local/directadmin/scripts/custom/email_create_post.sh chown diradmin:diradmin /usr/local/directadmin/scripts/custom/email_create_post.sh
Or open the file /usr/local/directadmin/scripts/custom/email_create_post.sh in an editor and add the following lines (somewhere after #!/bin/sh)
SCRIPT="/usr/local/directadmin/scripts/custom/directadmin-teach-sa/create_folders.sh"; [ -x "${SCRIPT}" ] && ${SCRIPT} "${user}@${domain}" >/dev/null 2>&1;
A cron scrtipt gets installed to /etc/cron.d/0teach-sa_cron. And it executes cron_sa_learn.sh once per hour.
cron_sa_learn.sh - a script to run with cron. The script goes through all Directadmin users and teach SpamAssassin per user bases. Every user has its own bayes data, stored under his/her own homedir.
IMPORTANT! The script requires root permissions and sudo installed on a server to run. It will use sudo to switch to user for teaching SpamAssassin.
That's it!
~~~ OLD WAY (may still work though) ~~~
Here you can find a guide on how to create a cronjob to use sa-learn to teach spamassassin. The step #1 guides how to create imap folders for it. To do a bulk update on your server with a number accounts you'd better have a script. And here we offer such a script.
#!/bin/bash ## ## Poralix.COM $ 2014-06-09 (support@poralix.com) ########################################################################### ## Linux Administrator At your service ## Server Management | Server Migration | Server Support | Server Setup ## Writing custom Plugins for Directadmin. ########################################################################### ## ## The script creates imap folders for all email accounts on the server ## according to this guide http://help.directadmin.com/item.php?id=358 ## for domain in `cat /etc/virtual/domains`; do username=`grep ^$domain: /etc/virtual/domainowners | cut -d\ -f2` echo "[+] Working with $domain owned by $username"; for data in `cat /etc/virtual/$domain/passwd`; do ebox=`echo $data | cut -d\: -f1`; maildir="`echo $data | cut -d\: -f6`/Maildir"; echo "[+][+] Working with $ebox@$domain with Maildir in $maildir"; [ -d "$maildir/.INBOX.teach-isspam" ] || mkdir -v $maildir/.INBOX.teach-isspam [ -d "$maildir/.INBOX.teach-isnotspam" ] || mkdir -v $maildir/.INBOX.teach-isnotspam chown -vR $username:mail $maildir/.INBOX.teach-* chmod -v 770 $maildir/.INBOX.teach-* c=`grep INBOX.teach-isspam $maildir/subscriptions -c` if [ $c -eq 0 ]; then echo INBOX.teach-isspam >> $maildir/subscriptions fi; c=`grep INBOX.teach-isnotspam $maildir/subscriptions -c` if [ $c -eq 0 ]; then echo INBOX.teach-isnotspam >> $maildir/subscriptions fi; done; done; exit 0;
Save it as create_sa-learn-folders.sh for example and run it:
chmod 700 create_sa-learn-folders.sh ./create_sa-learn-folders.sh
For now that's all. That's up to you to setup a cron task to teach SA as it suggested in the step #2 of the guide.