How to install and configure MailScanner, clamav and SpamAssassin using tar on Debian/Ubuntu

Posted by Md. Mahidul Hasan on 3:22 AM with No comments
How to install and configure MailScanner, clamav and SpamAssassin using tar on Debian/Ubuntu

Remove MailScanner:
root@mail:root@mail:~# /etc/init.d/mailscanner stop
root@mail:root@mail:~# apt-get remove mailscanner

Install MailScanner Dependencies:
root@mail:root@mail:~# apt-get install libconvert-tnef-perl libdbd-sqlite3-perl libfilesys-df-perl libmailtools-perl libmime-tools-perl libmime-perl libnet-cidr-perl libsys-syslog-perl libio-stringy-perl libfile-temp-perl
root@mail:root@mail:~# apt-get install gcc g++ cpp zlib1g-dev libgmp3-dev perl bzip2 zip make patch automake libhtml-template-perl perl-suid
root@mail:root@mail:~# apt-get install linux-headers-`uname -r` build-essential libnewt-dev libusb-dev

Install clamav:
root@mail:root@mail:~# adduser clamav
root@mail:root@mail:~# http://downloads.sourceforge.net/clamav/clamav-0.97.3.tar.gz

However, because apt resource is backdated 0.94, it is better to download latest tarball. after installing, use the following commands:
root@mail:root@mail:~# tar -zxvf clamav-0.97.3.tar.gz
root@mail:root@mail:~# cd clamav-0.97.3
root@mail:root@mail:~# ./configure
root@mail:root@mail:~# make
root@mail:root@mail:~# make install

Run the following command to update the ClamAV if needed
root@mail:root@mail:~# freshclam –v

Configuring MailScanner:
root@mail:root@mail:~# wget http://www.mailscanner.info/files/4/tar/MailScanner-install-4.82.6-1.tar.gz
root@mail:root@mail:~# tar -zxvf MailScanner-install-4.82.6-1.tar.gz
root@mail:root@mail:~# cd MailScanner-install-4.82.6
root@mail:root@mail:~# ./install.sh

Backup and edit MailScanner.conf
root@mail:root@mail:~# cp /opt/MailScanner/etc/MailScanner.conf /opt/MailScanner/etc/MailScanner.conf.bak
root@mail:root@mail:~# vim /opt/MailScanner/etc/MailScanner.conf

Set the following settings in /etc/MailScanner/MailScanner.conf  “or”

root@mail:root@mail:~# vim /opt/MailScanner/etc/MailScanner.conf
%org-name% = Bangladesh Online
%org-long-name% = Bangladesh Online
%web-site% = www.bol-online.com
Run As User = postfix
Run As Group = postfix
Incoming Queue Dir = /var/spool/postfix/hold
Outgoing Queue Dir = /var/spool/postfix/incoming
MTA = postfix
Virus Scanners = clamav
Spam List = SBL+XBL
SpamAssassin User State Dir = /var/spool/MailScanner/spamassassin

Tuning MailScanner:
root@mail:~# vim /opt/MailScanner/etc/MailScanner.conf
Virus Scanning = yes
Virus Scanners = clamav
Use SpamAssassin = yes
Ignore Spam Whitelist If Recipients Exceed = 50
Required SpamAssassin Score = 3
High SpamAssassin Score = 4
SpamAssassin Auto Whitelist = no
Spam Actions = deliver header "X-Spam-Status: Yes"
High Scoring Spam Actions = forward spam.bol@bol-online.com
Log Speed = no
Log Spam = yes
Log Non Spam = yes
Log Delivery And Non-Delivery = yes
Log Permitted Filenames = yes
Log Permitted Filetypes = yes
Log Permitted File MIME Types = yes
Log Silent Viruses = yes
Log Dangerous HTML Tags = yes
Log SpamAssassin Rule Actions = yes
SpamAssassin User State Dir = /var/spool/MailScanner/spamassassin

root@mail:root@mail:~# vim /opt/MailScanner/etc/filetype.rules.conf (type # beginning of the following lines)

     #deny   self-extract     No self-extracting archives            No self-extracting archives allowed
     #deny   executable       No executables                         No programs allowed
     #deny   ELF              No executables                         No programs allowed
     #deny   Registry         No Windows Registry entries            No Windows Registry files allowed

Then we will need to ensure that the user "postfix" can write to /var/spool/MailScanner/incoming and /var/spool/MailScanner/quarantine:

root@mail:root@mail:~# chown postfix.postfix /var/spool/MailScanner/incoming
root@mail:root@mail:~# chown postfix.postfix /var/spool/MailScanner/quarantine

SpamAssassin Configuration:
If you don't want to use spam assassign,
root@mail:~# vim /opt/MailScanner/etc/MailScanner.conf
Use SpamAssassin = no
                           
Postfix settings:
root@mail:root@mail:~# vim /etc/postfix/main.cf
header_checks = regexp:/etc/postfix/header_checks

Edir header_checks
root@mail:root@mail:~# vim /etc/postfix/header_checks

Add this line to the file, without it nothing will work:
/^Received:/ HOLD

Start MailScanner:
root@mail:root@mail:~# /opt/MailScanner/bin/check_mailscanner

Stop MailScanner:
root@mail:root@mail:~# pkill -9 MailScanner

“OR” Start the system as follows:
root@mail:root@mail:~# /etc/init.d/mailscanner start
root@mail:root@mail:~# /etc/init.d/postfix start

[Optional: Disable permission checks on MailScanner directories Comment out the lines that check directory permissions on /var/* in /etc/rc2.d/S20mailscanner]

Set MailScanner to start at boot ti.In the file /etc/default/mailscanner, make sure this is set to 1:
run_mailscanner=1

Install spamassassin:
root@mail:~# wget http://mirrors.ispros.com.bd/apache//spamassassin/source/Mail-SpamAssassin-3.3.2.tar.gz

Make directory for SpamAssassin and set permissions
root@mail:~# mkdir /var/spool/MailScanner/spamassassin
root@mail:~# chown postfix /var/spool/MailScanner/spamassassin

Reload mailq:
To see the que mail in postfix we use,
root@mail:~# mailq

To see the que mail in mailscanner we use,
root@mail:~# postqueue -p

Sometime mailscanner hangsup due to lots of mail que or low configuration server. To release this qued mail to the postfix mailq we use,
root@mail:~# postsuper -r ALL
root@mail:~# postsuper -h ALL