This page is part of the EmailServer article.
Amavisd is a mail filtering interface that allows an MTA such as Postfix to talk to specialzed external add-ons such as SpamAssassin or ClamAV amongst others. On its own, it doesn't do anything useful, but it will make our anstispam and antivirus tools work well together.
It used to require some work to install Amavisd-New but it now has been included in most distributions, so installing it along with its numerous dependencies is as simple as:
# yum -t install amavisd-new
Configuring Amavisd-New is simply a matter of editing its
$max_servers = 5;
$daemon_user = 'amavis';
$daemon_group = 'amavis';
$mydomain = 'example.com';
$MYHOME = '/var/amavis';
Here we tell Amavisd-New that it will be running under the
$mydomain = 'example.com';
@local_domains_maps = ( [".$mydomain", "example2.com", "example3.com"] );
$max_servers = 5;
This tells Amavisd-New to always fork 5 children waiting for our mails. This means that, at any time, we'll be able to process 5 emails simultaneously. If you don't have much RAM, you can lower this figure to
$sa_tag_level_deflt = undef;
$sa_tag2_level_deflt = 6.31;
Ensures that we always get X-Spam-Status and X-Spam-Level in our email headers, whatever the spam score, that anything above a spam score (see SpamAssassin) will be flagged as spam.
$sa_spam_subject_tag = '[SPAM] ';
This is what will be shown in the subject of an email detected as spam.
$final_virus_destiny = D_DISCARD;
We will quarantine messages containing viruses so they are not delivered to the user (when our antivirus will be installed).
@bypass_virus_checks_maps = (1);
We also disable virus checking for now because we haven't installed the antivirus yet and Amavisd-New will not let mail through if this option is disabled and there is no Antivirus.
$final_banned_destiny = D_BOUNCE;
$banned_filename_re = new_RE(
[ qr'^\.(rpm|cpio|tar)$' => 0 ],
[ qr'^\.(zip|rar|arc|arj|zoo)$'=> 0 ],
Here we make sure that emails containing attachments with banned extensions get bounced. While we'll probably end up trying to bounce viruses and spam, it's better to use this option to let legitimate senders who are sending us banned attachements that their messages did not get through.
We now have a couple of choices: sending our spam to the user with the modified subject line, or quarantine the message by sending it to a special user account.
Basic setup: spam email sent to user
The most basic setup is to let the user deal with the spam. The good thing about that is that they can judge if there is a false positive, and can still separate the spam by using filters in their mail clients to automatically move marked spam to a local folder.
$sa_kill_level_deflt = 10000;
This will make Amavisd-New ignore any action for spam scores below this figure, which is normally beyond the highest possible spam score.
Advanced setup: quarantine to a special account
If instead of cloggin the users with spam messages we want to move them to a special user account on the server, we need to modify the following in
$sa_kill_level_deflt = 6.31;
$final_spam_destiny = D_DISCARD;
virusalert : administrator
spam.police : administrator
Again, don't forget to rebuild the aliases database with
Configuring Postfix to use Amavisd-New
Now we need to let postfix know about Amavisd-New. Postfix communicates with external programs through TCP/IP ports. This method allows a clear separation of processes and their priviledges as each is running under its own account.
smtp-amavis unix - - y - 5 smtp
127.0.0.1:10025 inet n - y - - smtpd
Note: if you reduced the number of
content_filter = smtp-amavis:[127.0.0.0]:10024
Amavisd-New White and Black lists
If you want to make sure that some addresses always get through and that some always get banned, you will need to create a white list and a black list.
# touch /var/amavis/white.lst
# touch /var/amavis/black.lst
# chown amavis.amavis -R /var/amavis/
You need to make Amavisd-New know about those files. Edit
@whitelist_sender_maps = read_hash("$MYHOME/white.lst");
@blacklist_sender_maps = read_hash("$MYHOME/black.lst");
Now simply add each email address you want to unconditionnaly allow (white list)/block (black list) on a single line inside the relevant file.
Follow the simple testing procedures listed on the amavisd website to make sure that postfix and amavisd are properly configured:
The only error you may be getting is related to hte lack of antivirus, something we'll move onto now.