Spamassassin installation

Discussion Room for the Synology MailStation Package

Spamassassin installation

Postby momo » Fri Apr 17, 2009 9:31 am

Hi there,

well you can install Spamassassin via ipkg.

ipkg list | grep -i spamassassin
spamassassin - 3.1.8-1 - a spam filter for email which can be invoked from mail delivery agents

ipkg install spamassassin

it will install Spamassassin and modules dependent (perl 5.8.8 etc ...)

Then you have to configure SA :
it is done by editing local.cf in /opt/etc/spamassassin.

Here is my local.cf file :

Code: Select all
# This is the right place to customize your installation of SpamAssassin.
#
# See 'perldoc Mail::SpamAssassin::Conf' for details of what can be
# tweaked.
#
# Only a small subset of options are listed below
#
###########################################################################
#   Add *****SPAM***** to the Subject header of spam e-mails
#
rewrite_header Subject *****SPAM*****

#   Save spam messages as a message/rfc822 MIME attachment instead of
#   modifying the original message (0: off, 2: use text/plain instead)
#
report_safe 1

#   Set which networks or hosts are considered 'trusted' by your mail
#   server (i.e. not spammers)
#
# trusted_networks 212.17.35.


#   Set file-locking method (flock is not safe over NFS, but is faster)
#
# lock_method flock

#   Set the threshold at which a message is considered spam (default: 5.0)
#
required_score 5.0

#   Use Bayesian classifier (default: 1)
#
use_bayes 1
use_bayes_rules 1

#   Bayesian classifier auto-learning (default: 1)
#
bayes_auto_learn 1

#   Set headers which may provide inappropriate cues to the Bayesian
#   classifier
#
# bayes_ignore_header X-Bogosity
# bayes_ignore_header X-Spam-Flag
# bayes_ignore_header X-Spam-Status
skip_rbl_checks         0

ok_locales              fr  --- sorry i'm french :-)


Then you have to create a user (for me it is spamfilter).
after that you have to create a script (for me named spamfilter.sh) which is responsible to transfer to the user dedicated for spam.

Script can be found in spamassassin Wiki and is adapted to Synology.
mktemp package should be installed via ipkg.

Code: Select all
#!/bin/sh

SENDMAIL="/usr/syno/mailstation/sbin/sendmail -i"
SPAMASSASSIN=/opt/bin/spamc

COMMAND="$SENDMAIL $@"

USER=`echo $COMMAND |awk  '{print $NF}' | sed 's/@.*$//'`

NEW_COMMAND=`echo $COMMAND |awk  '{ $6="spamfilter";NF=6; print }'`
EX_TEMPFAIL=75
EX_UNAVAILABLE=69

umask 077

OUTPUT="`/opt/bin/mktemp /tmp/mailfilter.XXXXXXXXXX`"

if [ "$?" != 0 ]; then
  /usr/bin/logger -s -p mail.warning -t filter "Unable to create temporary file."
  exit $EX_TEMPFAIL
fi

# Clean up when done or when aborting.
trap "rm -f $OUTPUT" EXIT TERM

$SPAMASSASSIN -x -E -u $USER > $OUTPUT
return="$?"
if [ "$return" = 1 ]; then
  $NEW_COMMAND < $OUTPUT
  exit $?
elif [ "$return" != 0 ]; then
  /usr/bin/logger -s -p mail.warning -t filter "Temporary SpamAssassin failure (spamc returned $return)"
  exit $EX_TEMPFAIL
fi

$SENDMAIL "$@" < $OUTPUT
exit $?


This script is only replacing recipient with spamfilter user.

Change the right to spamfilter:spamfilter for script
chown spamfilter:spamfilter spamfilter.sh
chmod 744 spamfilter.sh

Then you have to modify master.cf in /usr/syno/mailstation/etc
replace
smtp inet n - n - - smtpd
by
smtp inet n - n - - smtpd -o content_filter=spamassassin

and add
spamassassin unix - n n - - pipe flags=Rq user=spamfilter argv=/opt/bin/spamfilter.sh -oi -f ${sender} ${recipient}

Well config for SA is ready.
Now you have to start Spamassassin, i do it with a script :

Code: Select all
echo "Starting spamd"
/opt/bin/spamd -d -c -m 1 --max-conn-per-child=100 --pidfile=/var/run/spamd.pid -p 783 -u spamfilter


It means that spamd is running as daemon, is creating user_preferences and is running as spamfilter.

For every users, you have to change owner and group of .spamassassin directory.
you should find this directory under /volume1/homes/xxx/.spamassassin

chown -R spamfilter:spamfilter .spamassassin

Don't forget to create Bayes DB with sa-learn.

Reload Postfix :
/usr/syno/mailstation/sbin/postfix reload

If all is working, you should see in the /var/log/messages file, entries like this :

for "non-spam" :
postfix/smtpd[14547]: connect from unknown[78.101.197.82]
postfix/smtpd[14547]: 113E8528A23: client=unknown[78.101.197.82]
postfix/cleanup[14551]: 113E8528A23: message-id=<B72BA7E3.FBE04FD2@chocofan.com>
postfix/qmgr[2221]: 113E8528A23: from=<wycirinlasq@chocofan.com>, size=2789, nrcpt=1 (queue active)
spamd[3967]: spamd: connection from localhost [127.0.0.1] at port 2022
spamd[3967]: spamd: setuid to xxx succeeded
spamd[3967]: spamd: processing message <B72BA7E3.FBE04FD2@chocofan.com> for xxx:1026
postfix/smtpd[14547]: disconnect from unknown[78.101.197.82]
spamd[3967]: spamd: clean message (0.0/5.0) for xxx:1026 in 1.1 seconds, 2729 bytes.
spamd[3967]: spamd: result: . 0 - HTML_MESSAGE,MIME_HTML_ONLY,NO_RECEIVED,NO_RELAYS scantime=1.1,size=2729,user=xxx,uid=1026,required_score=5.0,rhost=localhost,raddr=127.0.0.1,rport=2022,mid=<B72BA7E3.FBE04FD2@chocofan.com>,autolearn=ham
spamd[3966]: prefork: child states: I
postfix/pipe[14552]: 113E8528A23: to=<xxx@xxx.xx>, relay=spamassassin, delay=5.1, delays=3.5/0.08/0/1.5, dsn=2.0.0, status=sent (delivered via spamassassin service)
postfix/qmgr[2221]: 113E8528A23: removed
postfix/pickup[14521]: 38C5E528A2B: uid=1029 from=<wycirinlasq@chocofan.com>
postfix/cleanup[14551]: 38C5E528A2B: message-id=<B72BA7E3.FBE04FD2@chocofan.com>
postfix/qmgr[2221]: 38C5E528A2B: from=<wycirinlasq@chocofan.com>, size=2999, nrcpt=1 (queue active)
postfix/local[14569]: 38C5E528A2B: to=<xxx@xxx.xx>, relay=local, delay=0.12, delays=0.06/0.05/0/0.01, dsn=2.0.0, status=sent (delivered to maildir)
postfix/qmgr[2221]: 38C5E528A2B: removed

for spam :

postfix/smtpd[14976]: connect from xxx[xxx.xxx.xxx.xxx]
postfix/smtpd[14976]: 7196A528A29: client=xxx[xxx.xxx.xxx.xxx]
postfix/cleanup[14981]: 7196A528A29: message-id=<11267629.296163.1239709365194.JavaMail.www@wwinf1d18>
postfix/qmgr[14972]: 7196A528A29: from=<xxx@xxx.xx>, size=1075, nrcpt=1 (queue active)
postfix/smtpd[14976]: disconnect from xxx[xxx.xxx.xxx.xxx]
spamd[14753]: spamd: connection from localhost [127.0.0.1] at port 4036
spamd[14753]: spamd: setuid to xxx succeeded
spamd[14753]: spamd: processing message <11267629.296163.1239709365194.JavaMail.www@wwinf1d18> for xxx:1026
spamd[14753]: spamd: identified spam (1002.7/5.0) for xxx:1026 in 0.7 seconds, 1089 bytes.
Apr 14 13:42:51 spamd[14753]: spamd: result: Y 1002 - AWL,GTUBE,HTML_10_20,HTML_MESSAGE,HTML_SHORT_LENGTH,MISSING_SUBJECT,NO_RECEIVED,NO_RELAYS scantime=0.7,size=1089,user=xxx,uid=1026,required_score=5.0,rhost=localhost,raddr=127.0.0.1,rport=4036,mid=<11267629.296163.1239709365194.JavaMail.www@wwinf1d18>,autolearn=no
spamd[14749]: prefork: child states: I
postfix/pickup[14971]: 92F07528A2C: uid=1029 from=<xxx@xxx.xx>
postfix/cleanup[14981]: 92F07528A2C: message-id=<11267629.296163.1239709365194.JavaMail.www@wwinf1d18>
postfix/qmgr[14972]: 92F07528A2C: from=<xxx@xxx.xx>, size=3679, nrcpt=1 (queue active)
postfix/pipe[14982]: 7196A528A29: to=<xxx@xxx.xx>, relay=spamassassin, delay=2.3, delays=1.2/0.04/0/1.1, dsn=2.0.0, status=sent (delivered via spamassassin service)
postfix/qmgr[14972]: 7196A528A29: removed
postfix/local[14997]: 92F07528A2C: to=<spamfilter@xxx.xx>, orig_to=<spamfilter>, relay=local, delay=0.25, delays=0.03/0.16/0/0.05, dsn=2.0.0, status=sent (delivered to maildir)
postfix/qmgr[14972]: 92F07528A2C: removed

With this solution, you can forward your spam in the spamfilter mailbox and train Spamassassin periodically
sa-learn --showdots --spam /volume1/homes/spamfilter/new

You should train Spamassassin too with mails that are not spam in each mailbox :
sa-learn --showdots --ham /volume1/homes/xxx/new

you can check the status of SA with spamassassin --lint -D
and check the status of Bayes DB with :
sa-learn --dump magic

Hope this helps
ciaoooooo
"If you have a problem, if no one else can help and if you can find them,
maybe you can hire... The A-Team"
---
"Sodomy. One of the top 10 most common household accidents." House M.D
momo
Novice
Novice
 
Posts: 53
Joined: Mon Nov 26, 2007 11:49 am
Location: France - 06°12'54"E - 49°01'01"N

Re: Spamassassin installation

Postby Marcel » Thu Apr 23, 2009 10:20 am

Hey,

I was looking for some info for installins spamassassin.

So Thanks !!!
... but ... your 'speed' is somewhat too fast..

I understand the global idea, and proberly, when I start to get it installed it can work, but as a linux-nono I think the risk of crashing the system is too high to me.

Is there any info (step by step in more detail) on the web?
I did not find anything what was simple enough to me....

Thanks
Marcel
Beginner
Beginner
 
Posts: 27
Joined: Thu Mar 12, 2009 11:26 pm

Re: Spamassassin installation

Postby Alexander1974 » Sat Apr 25, 2009 6:15 pm

Yeaah,

Same for me !
Please do a DUMMY explanation !

Thanks,

Alexander
Regards,

Alexander from The Netherlands - Arnhem
DS710+ / 2x 1,5 Tb HDD / Gigabit LAN / Squeezebox / Popcorn Hour A-110
Alexander1974
I'm New!
I'm New!
 
Posts: 9
Joined: Sat Apr 25, 2009 6:09 pm

Re: Spamassassin installation

Postby Marcel » Sun May 10, 2009 9:34 pm

Hello

I tried to install:

Al seems to go OK, but after restarting, the mailserver stopped working.
in /vars/log messages, I found some errorlines:

May 10 21:53:40 spamc[3407]: connect(AF_INET) to spamd at 127.0.0.1 failed, retrying (#1 of 3): Connection refused
May 10 21:53:40 spamc[3405]: connect(AF_INET) to spamd at 127.0.0.1 failed, retrying (#1 of 3): Connection refused

These came 3 times and connection was aborting.

So I removed the lines I added in master.cf in /usr/syno/mailstation/etc
and the mailserver worked agian (pffff)

So what is wrong here?
Marcel
Beginner
Beginner
 
Posts: 27
Joined: Thu Mar 12, 2009 11:26 pm

Re: Spamassassin installation

Postby paultje_m » Thu Feb 18, 2010 4:51 pm

I think in my case Bayes is not working:
Code: Select all
sa-learn --dump magic -D


gives

Code: Select all
...
...
[5731] dbg: bayes: DB_File module not installed, cannot use bayes
[5731] dbg: config: score set 1 chosen.
[5731] dbg: bayes: DB_File module not installed, cannot use bayes
ERROR: Bayes dump returned an error, please re-run with -D for more information


How can I install the DB_File module?
paultje_m
I'm New!
I'm New!
 
Posts: 5
Joined: Wed Feb 17, 2010 11:13 am

Re: Spamassassin installation

Postby E-wawa.pl » Tue Mar 16, 2010 12:58 pm

This tutorial definietly needs an update!

I wonder if anyone has this working / xept the author!
User avatar
E-wawa.pl
Experienced
Experienced
 
Posts: 119
Joined: Fri Jan 15, 2010 2:34 pm

Re: Spamassassin installation

Postby HarryPotter » Tue Mar 16, 2010 5:35 pm

You should probably wait a couple of days. there are rumours that a new mailstation version will be released with spamassassin included.
*Please do not Private Message me for support questions; leave it on the forum so all members can learn. Thanks!*

DS712+ / DSM 4.2 3211 / 2 x HD204UI (RAID0) / LMS 7.7.2-007
DS110+ / DSM 4.2 3211 / HD154UI
DS408 / DSM 4.0 2228 / 3 x ST31000340AS (RAID0) + 1 x HDS721010KLA330
DS207+ / DSM 3.1.1636 / ST31000340AS + WD5000KS
DS-106x / DSM 4.0 2228 (from DS108j) /

2 Squeezebox 3 + Boom
Rapsody N35

APC Smart UPS SUA750i
User avatar
HarryPotter
Honorary Moderator
Honorary Moderator
 
Posts: 12322
Joined: Mon Oct 23, 2006 12:48 pm
Location: Switzerland

Re: Spamassassin installation

Postby Marcel » Tue Mar 16, 2010 7:49 pm

HarryPotter wrote:You should probably wait a couple of days. there are rumours that a new mailstation version will be released with spamassassin included.


This would be great. :)
For me, It is the only missing part of the Synology and the Mailstation. :(

Can't wait to get it !! :D

Can anyone confirm this :?:
Marcel
Beginner
Beginner
 
Posts: 27
Joined: Thu Mar 12, 2009 11:26 pm

Re: Spamassassin installation

Postby HarryPotter » Tue Mar 16, 2010 8:18 pm

*Please do not Private Message me for support questions; leave it on the forum so all members can learn. Thanks!*

DS712+ / DSM 4.2 3211 / 2 x HD204UI (RAID0) / LMS 7.7.2-007
DS110+ / DSM 4.2 3211 / HD154UI
DS408 / DSM 4.0 2228 / 3 x ST31000340AS (RAID0) + 1 x HDS721010KLA330
DS207+ / DSM 3.1.1636 / ST31000340AS + WD5000KS
DS-106x / DSM 4.0 2228 (from DS108j) /

2 Squeezebox 3 + Boom
Rapsody N35

APC Smart UPS SUA750i
User avatar
HarryPotter
Honorary Moderator
Honorary Moderator
 
Posts: 12322
Joined: Mon Oct 23, 2006 12:48 pm
Location: Switzerland

Re: Spamassassin installation

Postby Asboe » Wed Mar 17, 2010 7:47 am

Strange that "MailStation-20090911-015.spk" and "MailStation-20100317-017" are approachable same size. I would expect SpamAssassin to "weight" a little more...

Receiving mails over DS now include:
X-Spam-Checker-Version: SpamAssassin 3.2.5 (2008-06-10) on XXXServer
X-Spam-Level:
X-Spam-Status: No, score=0.9 required=5.0 tests=AWL,FUZZY_CREDIT autolearn=no version=3.2.5

Mysteriously :)

I wonder if this is without any options to tweak SpamAssassin :?:
I can't find them.

H/V Asboe
DS-209+II (4.2-3211) - 2x WDC WD20EADS 2TB
DS-107+(3.1-1636) - Samsung HD103SJ 1TB
DS-106 (2.0-0731) - WDC WD7500AAKS 750GB
DS-101j (2.0-0731) - Maxtor 6L300R0 300GB
User avatar
Asboe
Sharp
Sharp
 
Posts: 154
Joined: Sun Nov 05, 2006 8:46 am

Re: Spamassassin installation

Postby HarryPotter » Wed Mar 17, 2010 9:18 am

According to informations I found on the German forum, the spamassassin files are already included in the FW. The package does only activate it.

I couldnt find any options on the WebUI, but you can adjust the config files using CLI.
*Please do not Private Message me for support questions; leave it on the forum so all members can learn. Thanks!*

DS712+ / DSM 4.2 3211 / 2 x HD204UI (RAID0) / LMS 7.7.2-007
DS110+ / DSM 4.2 3211 / HD154UI
DS408 / DSM 4.0 2228 / 3 x ST31000340AS (RAID0) + 1 x HDS721010KLA330
DS207+ / DSM 3.1.1636 / ST31000340AS + WD5000KS
DS-106x / DSM 4.0 2228 (from DS108j) /

2 Squeezebox 3 + Boom
Rapsody N35

APC Smart UPS SUA750i
User avatar
HarryPotter
Honorary Moderator
Honorary Moderator
 
Posts: 12322
Joined: Mon Oct 23, 2006 12:48 pm
Location: Switzerland

Re: Spamassassin installation

Postby Marcel » Thu Mar 18, 2010 9:13 am

Great that Spamassassin is now available on the Synology. :D
In Mailstation, I see a Spamfiler option which van be set on or off.

Now I am wondering, what the default behavior is:
Is all spam dropped without a possibility to check false positives?
Is the spam-mail send to a special mail-account, and if so which one and how can I access it?
And last but nit least how can i change settings? Where can I find the files in which the settings are located?

Can anyone help/ give some info one these questions?
Thanks :!:
Marcel
Beginner
Beginner
 
Posts: 27
Joined: Thu Mar 12, 2009 11:26 pm

Re: Spamassassin installation

Postby HarryPotter » Thu Mar 18, 2010 9:51 pm

The filter is adding something like ***SPAM*** to the header and delivers the email.
*Please do not Private Message me for support questions; leave it on the forum so all members can learn. Thanks!*

DS712+ / DSM 4.2 3211 / 2 x HD204UI (RAID0) / LMS 7.7.2-007
DS110+ / DSM 4.2 3211 / HD154UI
DS408 / DSM 4.0 2228 / 3 x ST31000340AS (RAID0) + 1 x HDS721010KLA330
DS207+ / DSM 3.1.1636 / ST31000340AS + WD5000KS
DS-106x / DSM 4.0 2228 (from DS108j) /

2 Squeezebox 3 + Boom
Rapsody N35

APC Smart UPS SUA750i
User avatar
HarryPotter
Honorary Moderator
Honorary Moderator
 
Posts: 12322
Joined: Mon Oct 23, 2006 12:48 pm
Location: Switzerland

Re: Spamassassin installation

Postby GZZ » Fri Mar 19, 2010 2:05 pm

I have a mail that is tagged as spam, but I recieve this mail in my Inbox in RoundCube Webmail, how do you set spam mails to go to Unwanted emails / Junk folder. Do you just drag it to the folder anden den all tagged spam mails go to this folder ?

Second question, if you have a mail that is spam (but not tagged as so), how do you tag it as spam, so the filter know that future mails like this is spam ?

/Henrik
GZZ
I'm New!
I'm New!
 
Posts: 9
Joined: Thu Sep 17, 2009 9:10 pm


Return to MailStation

Who is online

Users browsing this forum: No registered users and 0 guests