On m'a demandé de mettre en place une solution de filtre anti-spam sur le serveur de mail courier-mta. Vu que le projet dspam semble ne plus être maintenu j'ai donné une chance à un des plus populaire, à savoir : SpamAssassin. L'installation et le paramétrage ont été effectués sur une distribution Debian.
On utilisera le MDA (Mail Delivery Agent) Maildrop pour regiriger nos mails à notre service SpamAssassin.
echo "|/usr/bin/maildrop" | sudo tee -a /var/vmail/mydomain.net/shebang.thedolphins/.courier
import HOME import USER if ( /^To: .*shebang.thedolphins@mydomain\.net.*/ && $SIZE < 256000 ) { #won't work with vmail users, to avoid "spamd: handle_user (userdir) unable to find user:" message #xfilter "/usr/bin/spamc -u $USER" xfilter "/usr/bin/spamc" } #Optional : if we want, detected spams could be moved to a specific folder : #if ( /^X-Spam-Status: Yes/ ) #{ # to "$HOME/Maildir/.SpamAssassin/" #}
root@host:~# apt-get install spamassassin spamc
root@host:~# su - vmail/
vmail@host:~$ mkdir .spamassassin/
vmail@host:~$ chmod -R ugo+w .spamassassin/
root@host:~# mkdir /var/log/spamassassin/; groupadd spamd; useradd -g spamd -s /bin/false -d /var/log/spamassassin spamd; chown spamd:spamd /var/log/spamassassin
rewrite_header Subject *****SPAM***** report_safe 0
OPTIONS="--create-prefs --max-children 2 --username spamd -H /var/log/spamassassin/ -s /var/log/spamassassin/spamd.log" CRON=1
root@host:~# systemctl restart spamassassin
#! /bin/bash #Mails in Spam folder are Spams sa-learn --no-sync --spam /var/vmail/mydomain.net/shebang.thedolphins/Maildir/.Spam/{cur,new} #Mails in Nospam folder are legit emails sa-learn --no-sync --ham /var/vmail/mydomain.net/shebang.thedolphins/Maildir/.Nospam/{cur,new} #Once processed as spam we put mails in trash folder for i in /var/vmail/mydomain.net/shebang.thedolphins/Maildir/.Spam/{cur,new}/*; do mv "$i" /var/vmail/mydomain.net/shebang.thedolphins/Maildir/.Trash/cur/ done #Once processed as legit we put mails in INBOX for i in /var/vmail/mydomain.net/shebang.thedolphins/Maildir/.Nospam/{cur,new}/*; do mv "$i" /var/vmail/mydomain.net/shebang.thedolphins/Maildir/new/ done
*/15 * * * * root /usr/local/sbin/spamassassin_learn.sh
Contact :