Filtering spam emails with Spamassassin
Written by ⓘⓓⓔⓝⓣⓛⓤⓓ - -

Installing spamassassin
Where talking about Debian here ... :apt-get install spamassassinOne configuration step is to enable spamassassin in its configuration file
/etc/default/spamassassin
# sed -i "s/ENABLED=0/ENABLED=1/g" /etc/default/spamassassinAnd then the
spamd
service that must be launched with :# service spamassassin startYou can check that the
spamd
daemon is listening to inputs on loopback
address :# netstat -ntpl | grep spamdtcpThe version installed is :
0 0 127.0.0.1:783 0.0.0.0:* LISTEN 20892/spamd.pid
# spamassassin --version
SpamAssassin version 3.3.2 running on Perl version 5.14.2
Filtering SMTP content through spamassassin
I'll have to configure a service for smtp in /etc/postfix/master.cf
by adding a -o
option :smtp inet n - - - - smtpdAnd configure what spamassassin stands for in
-o content_filter=spamassassin
submission inet n - - - - smtpd
-o smtpd_tls_security_level=encrypt
-o smtpd_sasl_auth_enable=yes
-o smtpd_client_restrictions=permit_sasl_authenticated,reject
-o content_filter=spamassassin
smtps inet n - - - - smtpd
-o smtpd_tls_wrappermode=yes
-o smtpd_sasl_auth_enable=yes
-o smtpd_client_restrictions=permit_sasl_authenticated,reject
-o content_filter=spamassassin
/etc/postfix/master.cf
by adding it at the end of the file :## SPAMASSASSINNB : I edited the line to have it fit in the
spamassassin unix - n n - - pipe user=debian-spamd argv=/usr/bin/spamc -f -e /usr/sbin/sendmail \
-oi -f ${sender} ${recipient}
<pre>
section but I guess that it is better if the line starting with "user=
" and ending with "${recipient}
" is a one-liner.debian-spamd
is the user created by the apt-get install
.# getent passwd | grep debian-spamd
debian-spamd:x:112:116::/var/lib/spamassassin:/bin/sh
Result
You may find some interesting logs in/var/log/mail.log
Nov 17 19:30:44 postfix/pipe[32112]: 596F361DA4: to=<xxx@lebegue.org>, relay=spamassassin, delay=1.1, delays=0.76/0.02/0/0.29, dsn=2.0.0, status=sent (delivered via spamassassin service)
Nov 17 19:35:14 postfix/pipe[5098]: C8A6761D6F: to=<xxx@lebegue.org>, relay=spamassassin, delay=519, delays=518/0.01/0/0.63, dsn=2.0.0, status=sent (delivered via spamassassin service)
Updating filters
Once in a while, or through acron
entry, you can update filters with this command (man pages are well written) :sa-update && service spamassassin reload
Learning behaviour
Look at man pages forsa-learn
to improve spamassassin bayesian filters efficiency.