Home > Articles > Security > Network Security

  • Print
  • + Share This
This chapter is from the book

SpamAssassin Configuration

In the last part of this chapter, we look at the SpamAssassin application: how to use it and how to integrate it into your mail infrastructure.

SpamAssassin is broken down into the following major user-accessible components:

  • spamassassin The Perl program meant to be used as a per-user command line interface. It is not designed to be used in high-volume environments; instead, use spamc/spamd or call the libraries directly.
  • spamc A very efficient interface to the Spamassassin processor, written in C. It is meant to be called from scripts and designed to communicate with spamd, the daemonized version of spamassassin.
  • spamd The daemonized version of the spamassassin program. It is meant to be used with spamc, but it doesn't have to be. spamd is designed for high-volume environments, where speed is of the essence. It is optimized for running as a standalone program, where clients would connect to it on port 783. There are options for connecting to a MySQL database or LDAP server for large installations.
  • sa-learn The program that populates or retrains SpamAssassin's Bayesian classifier database of spam.

Along with these four programs, which can be run by the end-user/administrator, the SpamAssassin libraries themselves are also available. These are the Perl libraries that actually perform the analysis and scoring of email messages. An example of a user program that calls the libraries directly is amavisd-new, one of the SpamAssassin MTA interfaces we cover. The end user can write programs in Perl that execute SpamAssassin library calls, enabling custom programs to be written for processing email. The complete set of command options for spamassassin, spamc, spamd and sa-learn commands are contained in Appendix D, "SpamAssassin Command Line Interface Reference."

The SpamAssassin Command Line Interface

The spamassassin command line interface (CLI) is meant for users who have command line access to the machine that houses their email box. Alternatively, the CLI could be used to process messages for testing purposes or in a setup with a small number of users. The Procmail, forwarding, or .qmail functions in MTAs invoke the spamassassin command to process messages when SpamAssassin is not set up to be run at MTA time for the entire organization. For example, you would use the CLI if you were not integrating SpamAssassin into your MTA via milter, amavisd-new, or Qmail-Scanner.

The spamassassin command line interface can be used for the following purposes:

  • To identify a message as spam to collaborative filtering services
  • To retrain the internal Bayesian filters
  • To send a warning message to spam senders
  • To add addresses to whitelists/blacklists

Running SpamAssassin via Procmail

We will use the example of a per-user installation, where we had a small number of users or we wanted to test SpamAssassin prior to rolling it into full production. If you were running Sendmail or Postfix and were set up to call procmail as your MDA, this could easily be done by using the following Procmail recipe:

| /usr/local/bin/spamassassin

/usr/local/bin/spamassassin could be replaced with /usr/local/bin/spamc, the fast interface to spamassassin, if desired. This recipe could alternatively be placed in /etc/procmailrc, which would cause spamassassin to be invoked for all users. qmail installations would use the .qmail functionality outlined next.

Running SpamAssassin in qmail

In a qmail installation, if you wanted to have SpamAssassin process your messages as a regular user, you would place something like this in the .qmail file:

|/usr/local/bin/spamassassin -P | maildir ./Maildir/

This example would route all messages through spamassassin, outputting messages in the maildir formatted mailbox located in the user's home directory in folder called Maildir.


sa-learn is used by a command line user to retrain the Bayesian filters. It accepts a file name as an argument, or messages can be piped to it if desired. It accepts a number of options, the most useful of which are --ham for messages that need to be reclassified as non-spam and --spam for messages that were mistakenly classified as spam. For example, if you wanted to submit a mail message contained in the file called spam.txt in your home directory, you would execute the following command:

/usr/local/bin/sa-learn --spam spam.txt

This would be used for reclassifying a message that SpamAssassin misidentified as spam.

  • + Share This
  • 🔖 Save To Your Account