Installation of SpamAssassin on DirectAdmin


In this guide I will be explaining how to install and configure SpamAssasin on a Direct Admin based server running CentOS.

SpamAssasin is used for e-mail spam filtering based on content-matching rules. SpamAssassin uses a variety of spam-detection techniques, that includes DNS-based and fuzzy-checksum-based spam detection, Bayesian filtering, external programs, blacklists and online databases.

The program can be integrated with the mail server to automatically filter all mail for a site. It can also be run by individual users on their own mailbox. SpamAssassin is highly configurable; if used as a system-wide filter it can still be configured to support per-user preferences.

Spam Assassin is a great anti-spam tool. We recommend to activate it as soon as you create an account or log in for the first time. We also recommend you read the following article, which outlines further anti spam measures.


Note: This guide assumes you are familiar with SSH and basic command line navigation. These instructions apply primarily to customers who have Virtual Private Servers or Dedicated servers. If you do not have root-level access you will not be able to make these changes.


Installation

Begin Installation:

Install spamd and spamc:

cd /usr/local/directadmin/scripts
./spam.sh

Missing PERL modules:

If you get errors building spamd relating to missing perl modules, try using cpan to install them. If you have never run cpan before, set cpan to follow prerequisites, to speed up the process:

[server]# cpan
cpan> o conf prerequisites_policy follow
cpan> o conf commit

Then install the required modules:

export PERL_EXTUTILS_AUTOINSTALL="--defaultdeps"
cpan -i Archive::Tar Digest::SHA Mail::SPF IP::Country Net::Ident IO::Socket::INET6 Compress::Zlib Mail::DKIM LWP::UserAgent HTTP::Date Encode::Detect ExtUtils::MakeMaker NetAddr::IP Mail::SpamAssassin::Plugin::Razor2 Razor2::Client::Agent IO::Socket::SSL DBI

Or, as an alternative to using cpan, CentOS boxes can also use this:

yum -y install perl-ExtUtils-MakeMaker perl-Digest-SHA perl-Net-DNS perl-NetAddr-IP perl-Archive-Tar perl-IO-Zlib perl-Digest-SHA perl-Mail-SPF perl-IP-Country perl-Razor2 perl-Net-Ident perl-IO-Socket-INET6 perl-IO-Socket-SSL perl-Mail-DKIM perl-DBI perl-Encode-Detect perl-HTML-Parser perl-HTML-Tagset perl-Time-HiRes perl-libwww-perl

Installation continued

When the PERL modules have been installed you can start the installation routine again:

./spam.sh

If the installation routine asks you:

Are you ready for manual configuration? [yes] no

be sure to type "no" and press enter. Only use "yes" if you really know what you're doing. The default options are going to be the most reliable.


Configuration

Uncomment Spamassasin directive in exim.conf

In order to get exim to use the spamd program, you'll need to make some changes in your /etc/exim.conf. Uncomment the following section:

# Spam Assassin
#spamcheck_director:
#  driver = accept
#  condition = "${if and { \
#      {!def:h_X-Spam-Flag:} \
#      {!eq {$received_protocol}{spam-scanned}} \
#      {!eq {$received_protocol}{local}} \
#      {exists{/home/${lookup{$domain}lsearch{/etc/virtual/domainowners}{$value}}/.spamassassin/user_prefs}} \
#      {<{$message_size}{100k}} \
#    } {1}{0}}"
#  retry_use_local_part
#  transport = spamcheck
#  no_verify

Change the above to:

# Spam Assassin
spamcheck_director:
  driver = accept
  condition = "${if and { \
      {!def:h_X-Spam-Flag:} \
      {!eq {$received_protocol}{spam-scanned}} \
      {!eq {$received_protocol}{local}} \
      {exists{/home/${lookup{$domain}lsearch{/etc/virtual/domainowners}{$value}}/.spamassassin/user_prefs}} \
      {<{$message_size}{100k}} \
     } {1}{0}}"
  retry_use_local_part
  transport = spamcheck
  no_verify

Restart EXIM:

/sbin/service exim restart

Start SPAMD:

/usr/bin/spamd -d -c  -m 15

Filter Foreign Language Spam:

By default, SpamAssassin treats all languages equally. But you can configure it to parse each message and determine the language used. If it is not one of the "allowed" languages, SpamAssassin automatically adds a few points the message's spam score. If SpamAssassin is not sure about the language used, no points are assigned.

To have SpamAssassin filter out mail in foreign tongues:

  • Edit /etc/mail/spamassassin/local.cf in your favorite editor.
  • If not present, add "ok_languages " on a line of itself.
  • List the languages (from the list below) you want to accept, separated by spaces (To accept mail in English, German, Latin, Thai and Swedish, for example, use ok_languages en de la th sv.

Addon Plugins:

Vipul's Razor - a distributed, collaborative, spam detection and filtering network. Through user contribution, Razor establishes a distributed and constantly updating catalogue of spam in propagation that is consulted by email clients to filter out known spam. Detection is done with statistical and randomized signatures that efficiently spot mutating spam content. User input is validated through reputation assignments based on consensus on report and revoke assertions which in turn is used for computing confidence values associated with individual signatures.

Razor2, is installed by default when following the instructions above. To install seperately, please enter:
yum install pyzor perl-Razor-Agent

The Distributed Checksum Clearinghouses or DCC - an anti-spam content filter that runs on a variety of operating systems. The counts can be used by SMTP servers and mail user agents to detect and reject or filter spam or unsolicited bulk mail. DCC servers exchange or "flood" common checksums. The checksums include values that are constant across common variations in bulk messages, including "personalizations."

Needs to be built manually. Only the dccproc binary is required. The DCC website can be found here.


You have now succesfully installed and configured Spamassasin on your DirectAdmin based server. You can configure Spamassasin from within your DirectAdmin control panel.


Possible Errors:

In case the following error appears:

http: GET 3.3 request failed: 400 URL must be absolute: 400 URL must be absolute
error: no mirror data available for channel updates.spamassassin.org
channel: MIRRORED.BY contents were missing, channel failed

Please install the missing rules set, by issuing the following commands

cd /root
wget http://files1.directadmin.com/services/custombuild/Mail-SpamAssassin-rules-3.3.2-r1104058.tar.gz
wget http://files1.directadmin.com/services/custombuild/Mail-SpamAssassin-rules-3.3.2-r1104058.tar.gz.asc
wget http://files1.directadmin.com/services/custombuild/Mail-SpamAssassin-rules-3.3.2-r1104058.tar.gz.md5
wget http://files1.directadmin.com/services/custombuild/Mail-SpamAssassin-rules-3.3.2-r1104058.tar.gz.sha1
/usr/bin/sa-update --install Mail-SpamAssassin-rules-3.3.2-r1104058.tar.gz
/usr/bin/sa-update --nogpg

Control Panel Configuration

Enable or Disable Spam Assassin:

  1. Login to DirectAdmin
  2. Click the Spam Assassin link
  3. Simply hit save on the button to enable SpamAssassin
  4. Click Disable, then save SpamAssassin to disable

Basic Configuration Options:

  • required_score - Defines the required score for Spam Assassin, 5 is default, and is fairly aggressive. It would be suitable for a single user, but an ISP should set the default to be more lenient (8.0 or 10.0). 1 is the most strict (lets the least amount of spam though, may filter too much), 10 is the least strict (lets the most amount of spam though, may filter too little).
  • whitelist_from - Allows email from this address or domain, syntax is "whitelist_from user@domain.com"
  • blacklist_from - Denys email from this address or domain, syntax is "blacklist_from user@domain.com"

Wildcards

When you add the addresses to the blacklist, use * as a wildcard to represent multiple characters and ? to represent a single-character wildcard.

The following examples demonstrate how to properly use wildcards in the blacklist:

  • user@example.com - Blacklists a single email address.
  • *@example.com - Blacklists all the addresses at example.com.
  • ?ser@example.com - For example, User@example.com would be blacklisted, but AUser@example.com would not be blacklisted.
  • installation, spamassasin, e-mail, directadmin
  • 7 Users Found This Useful
Was this answer helpful?

Related Articles

Installation Clam Anti Virus (ClamAV) on DirectAdmin / CentOS

Clam AntiVirus is a popular open source (GPL) anti-virus toolkit for UNIX, designed for e-mail...

Installation Rootkit Hunter (rkhunter) on CentOS

  Rootkit Hunter (rkhunter) is a Unix-based tool that scans for rootkits, backdoors and possible...

Installation Rootkit Hunter (rkhunter) on CentOS

  Rootkit Hunter (rkhunter) is a Unix-based tool that scans for rootkits, backdoors and possible...

Mounting Partitions in CentOS 5.x

This is a basic security tip that can be executed to help protect your system. This is not an...

Binding multiple IPs to one interface in Centos

The steps to add additional IP's to one network card / interface in Centos are as follows:1.)...