How to setup Mailscanner, ClamAV, Postfix, SpamAssassin

Here's my personal notes from setting up a pretty effective spam filter. Hope this helps someone because I know I had very little help.

After Redhat Enterprise version 4 setup

yum update

go to http://www.mailscanner.info/, click on downloads. Copy url of most recent version for redhat/fedora

cd /usr/src
wget <>

yum install rpm-build gcc
tar xvzf Mailscanner....tar.gz
./install.sh

Ensure selinux is disabled

run 'setup' and remove sendmail from system services startup after MailScanner install

yum install postfix

edit /etc/postfix/main.cf
relay_recipient_maps = hash:/etc/postfix/valid-users
show_user_unknown_table_name=no
inet_interfaces = all
mydestination = $myhostname, localhost.$mydomain, localhost
relay_recipient_maps = hash:/etc/postfix/valid-users
smtpd_error_sleep_time = 5s
smtpd_soft_error_limit = 2
smtpd_hard_error_limit = 5
show_user_unknown_table_name=no

Create a file /etc/postfix/valid-users
And edit it to add a list of your valid users like this:
user@example.com X
user2@example.com X

Change the file from a “flat” file to a database by typing:
Postmap valid-users
This will create a file called valid-users.db

If you do not want to use DNS to resolve your domain names then do this:
edit /etc/postfix/transport
add your domains like this:
example.com smtp:[10.10.10.10]
mail.example.com smtp:[192.168.1.1]

edit /etc/postfix/main.cf
transport_maps = hash:/etc/postfix/transport

postmap transport (this will create a file called transport.db)

If you want to use DNS to resolve your domains (or don’t care either way) then do this:
Edit /etc/postfix/relay_domains
Add your domains like this:
example.com, mail.example.com

Edit /etc/postfix/main.cf
relay_domains = /etc/postfix/relay_domains

Start Postfix with “postfix start”

Test Postfix before going to the next step. Note that computers on the same subnet as your spam filter are “trusted” so you won’t get any relay access denied errors unless you’re testing from an external source.

Stop Postfix with “postfix stop”

Install SpamAssassin if this hasn’t been done yet.

Install ClamAV
yum install clamav clamav-update clamav-server
freshclam

edit /etc/MailScanner/virus.scanners.conf so that the line regarding clamav reads:
clamav /usr/lib/MailScanner/clamav-wrapper /usr


Configure MailScanner with Postfix
(taken from http://www.mailscanner.info/postfix.html)

edit /etc/postfix/main.cf
header_checks = regexp:/etc/postfix/header_checks

In the file /etc/postfix/header_checks add this line:
/^Received:/ HOLD  tells mail to hold in queue for scanning

In your MailScanner.conf file (probably in /etc/MailScanner) there are 6 settings you need to change. They are all really near the top of the file. The settings are
Run As User = postfix
Run As Group = postfix
Incoming Queue Dir = /var/spool/postfix/hold
Outgoing Queue Dir = /var/spool/postfix/incoming
MTA = postfix
SpamAssassin User State Dir = /var/spool/MailScanner/spamassassin
You will need to ensure that the user "postfix" can write to /var/spool/MailScanner/incoming and /var/spool/MailScanner/quarantine:
chown postfix.postfix /var/spool/MailScanner/incoming
chown postfix.postfix /var/spool/MailScanner/quarantine
chown postfix.postfix /var/spool/MailScanner/spamassassin (not sure if this is required)
If you upgrade your copy of MailScanner, unfortunately these directories will be changed back to being owned by root, so you will have to do those 3 commands again.
run 'setup' and add MailScanner to system services startup

If you are switching from sendmail to postfix then you will need to change the ownership of /var/spool/MailScanner/incoming/ SpamAssassin.cache.db to postfixostfix


Highlight Phishing Fraud = no
Virus Scanners = clamav
Maximum Archive Depth = 0
Sign Clean Messages = no
Spam List =
Spam Lists To Reach High Score =
Use SpamAssassin = yes
Required SpamAssassin Score =
High SpamAssassin Score =
SpamAssassin Auto Whitelist = no
High Scoring Spam Actions = forward spam@example.com
Notify Senders = no

Edit /etc/MailScanner/rules/spam.whitelist.rules

# This is where you can build a Spam WhiteList
# Addresses matching in here, with the value
# "yes" will never be marked as spam.
#From: 152.78. yes
#From: 130.246. yes
FromOrTo: default no
From: *@hotmail.com yes

Reboot the machine and all should be good!

Check out the log in /var/log/maillog

Posted in |

0 comments: