Postfix+Amavisd-new+Spamassasin+Clamav

Since I had to disable the PTR check in Postfix at Binware because in Spain 90% of mail servers are badly configured and they were all rejected, and now we have lot of spam.

So I decided to install Spamassassin and Clamav to detect and reject some of this spam.

First of all, we need to install needed packages:

apt-get install spamassassin amavisd-new clamav clamav-daemon

We will begin configuring amavisd-new, the configuration files are at /etc/amavis/conf.

In file 20-debian_defaults I changed the header that will be added to each mail processed:

$X_HEADER_LINE = "AntiSpam/Antivirus Scanner at $mydomain";

We need to activate antispam and antivirus check in amavis, this is found in file 15-content_filter_mode. We need to uncomment @bypass_virus_checks_maps and @bypass_spam_checks_maps. The file will look like this:

use strict;
 
# You can modify this file to re-enable SPAM checking through spamassassin
# and to re-enable antivirus checking.
 
#
# Default antivirus checking mode
# Please note, that anti-virus checking is DISABLED by
# default.
# If You wish to enable it, please uncomment the following lines:
 
 
@bypass_virus_checks_maps = (
   \%bypass_virus_checks, \@bypass_virus_checks_acl, \$bypass_virus_checks_re);
 
 
#
# Default SPAM checking mode
# Please note, that anti-spam checking is DISABLED by
# default.
# If You wish to enable it, please uncomment the following lines:
 
 
@bypass_spam_checks_maps = (
   \%bypass_spam_checks, \@bypass_spam_checks_acl, \$bypass_spam_checks_re);
 
1;  # ensure a defined return

By default, amavis will use the hostname for $mydomain, but thats not what I want, so I edited file 05-domain_id, setting $mydomain to binware.org

use strict;
 
# $mydomain is used just for convenience in the config files and it is not
# used internally by amavisd-new except in the default X_HEADER_LINE (which
# Debian overrides by default anyway).
 
$mydomain = 'binware.org';
 
# amavisd-new needs to know which email domains are to be considered local
# to the administrative domain.  Only emails to "local" domains are subject
# to certain functionality, such as the addition of spam tags.
#
# Default local domains to $mydomain and all subdomains.  Remember to
# override or redefine this if $mydomain is changed later in the config
# sequence.
 
@local_domains_acl = ( ".$mydomain" );
 
1;  # ensure a defined return

Next step is to add the clamav user to the amavis group, so that amavis can call clamav

adduser clamav amavis

Now it’s time to configure postfix. The first file to edit is main.cf:

# Amavisd-new
content_filter = amavis:[127.0.0.1]:10024

And in master.conf add this at the end of file:

amavis unix - - - - 2 smtp
  -o smtp_data_done_timeout=1200
  -o smtp_send_xforward_command=yes
 
127.0.0.1:10025 inet n - - - - smtpd
  -o content_filter=
  -o local_recipient_maps=
  -o relay_recipient_maps=
  -o smtpd_restriction_classes=
  -o smtpd_client_restrictions=
  -o smtpd_helo_restrictions=
  -o smtpd_sender_restrictions=
  -o smtpd_recipient_restrictions=permit_mynetworks,reject
  -o mynetworks=127.0.0.0/8
  -o strict_rfc821_envelopes=yes
  -o smtpd_bind_address=127.0.0.1

That’s all! Now restart services:

/etc/init.d/clamav-daemon restart
/etc/init.d/clamav-freshclam restart
/etc/init.d/amavis restart
/etc/init.d/postfix restart

Leave a Reply