Send off spam using Linux

If you’ve had an e-mail address for some time, chances are you have been the victim of unsolicited junk e-mail — otherwise known as spam. Removing spam can become a tiresome chore, and filtering for it using traditional filters is often ineffective and complicated. Over the next two columns we will look at some effective methods to filter spam from your inbox.

Included on this month’s cover CD is a copy of SpamAssassin (, an intelligent spam detection tool which employs a variety of methods to identify e-mail as spam. Using a scoring system, SpamAssassin assigns points for various common characteristics of spam to generate a total score for each e-mail you receive.

If an e-mail crosses a threshold score (by default, 5 points) it is marked as spam. Examples of point scoring offences include falsified e-mail headers, repeated phrases and misuse of HTML. SpamAssassin attaches a report to the top of a spam e-mail providing a breakdown of the reasons for the classification.

To compile SpamAssassin, copy the file from the cover CD to your hard disk and type the following commands in a shell:

$ tar xvfz Mail-SpamAssassin-2.53.tar.gz
$ cd Mail-SpamAssassin-2.53/
$ perl Makefile.PL
$ make

To install SpamAssassin, change to the superuser using the ‘su’ command and type the following:

$ make install

If you wish to test SpamAssassin, save a spam e-mail you have received to a file and call it spam.txt. To test SpamAssassin, type in a shell:

$ spamassassin

The e-mail will be written to the screen. Scroll back to the top of the e-mail and you will see some headers attached by SpamAssassin that are similar to the following:

X-Spam-Flag: YES
X-Spam-Status: Yes, hits=6.3 required=5.0

These headers indicate the e-mail was classified as spam because it scored 6.3 points, more than the required 5.0. Below these headers is a full breakdown of the points scored by the e-mail.

Filtering spam

Now that SpamAssassin is installed and working, you can begin employing it to filter incoming spam. Before configuring your e-mail client to use SpamAssassin, you should create a folder in which to store identified spam. Although SpamAssassin is very good at differentiating between spam and normal e-mail, occasionally it can be wrong. Maintaining a separate spam folder gives you a second chance to identify any normal e-mail mistakenly classified as spam.

You’ll find instructions for configuring KMail and Evolution to use SpamAssassin below, but users of other e-mail clients should be able to adapt these instructions for their own clients.


To configure KMail to use SpamAssassin, you need to create two filters by selecting Settings-Configure Filters from the menu. Click the New button located in the lower left corner to create a new filter. The first filter should be added at the top of your filter list so that it is the first to process new e-mails.

Set the filter criteria to “” “matches regular exp.” “.” and set the filter action to “pipe through”. Set the command to “spamassassin”. Uncheck the “If this filter matches” box. Click the Apply button to save the filter. This filter will run SpamAssassin on all incoming e-mail because the criteria will be true for any message.

The second filter should follow the newly created SpamAssassin filter and will move e-mail classified as spam into your spam folder. Create a new filter and set the criteria to “X-Spam-Flag” “equals” “YES” and set the action to “move to folder”. Set the folder to your spam folder.


Evolution does not allow an external command to modify an e-mail, so you must use SpamAssassin in a slightly different way. SpamAssassin can be made to return a simple true/false verdict with the addition of a “-e” switch to the spamassassin command.

To create a filter in Evolution, select Tools-Filters from the menu. Click the Add button and title the filter ‘SpamAssassin’. Set the criteria located in the top half of the window to “Pipe Message To Shell Command” “spamassassin -e”. Set the next box to “returns greater than” and set the final value to “0”. In the Action box located below, set the action to “Move to Folder” and select the “Spam” folder from the available list. To save the filter, click the OK button.

Now all that’s left to do is to sit back and wait for a spam to arrive. In the future you should see all your spam piling up in the new spam folder. In next month’s Linux Here’s How we’ll look at configuring SpamAssassin to be more precise, as well as using SpamAssassin with the procmail e-mail filter.

Join the PC World newsletter!

Error: Please check your email address.

Our Back to Business guide highlights the best products for you to boost your productivity at home, on the road, at the office, or in the classroom.

Keep up with the latest tech news, reviews and previews by subscribing to the Good Gear Guide newsletter.

Alastair Cousins

PC World
Show Comments

Cool Tech

Lexar® Professional 1000x microSDHC™/microSDXC™ UHS-II cards

Learn more >

D-Link PowerLine AV2 2000 Gigabit Network Kit

Learn more >

D-Link TAIPAN AC3200 Ultra Wi-Fi Modem Router (DSL-4320L)

Learn more >

Crucial® BX200 SATA 2.5” 7mm (with 9.5mm adapter) Internal Solid State Drive

Learn more >

Xiro Drone Xplorer V -3 Axis Gimbal & 1080p Full HD 14MP Camera

Learn more >

ASUS ROG Swift PG279Q – Reign beyond virtual world

Learn more >

Gadgets & Things

Lexar® Professional 1000x microSDHC™/microSDXC™ UHS-II cards

Learn more >

Lexar Professional 2000x SDHC™/SDXC™ UHS-II cards

Learn more >


Learn more >

Family Friendly

ASUS VivoPC VM62 - Incredibly Powerful, Unbelievably Small

Learn more >

Lexar® Professional 1000x microSDHC™/microSDXC™ UHS-II cards

Learn more >

Lexar Professional 2000x SDHC™/SDXC™ UHS-II cards

Learn more >

Stocking Stuffer

Lexar Professional 2000x SDHC™/SDXC™ UHS-II cards

Learn more >

Lexar® Professional 1000x microSDHC™/microSDXC™ UHS-II cards

Learn more >

Christmas Gift Guide

Click for more ›

Most Popular Reviews

Best Deals on PC World

Latest News Articles


GGG Evaluation Team

Kathy Cassidy


First impression on unpacking the Q702 test unit was the solid feel and clean, minimalist styling.

Anthony Grifoni


For work use, Microsoft Word and Excel programs pre-installed on the device are adequate for preparing short documents.

Steph Mundell


The Fujitsu LifeBook UH574 allowed for great mobility without being obnoxiously heavy or clunky. Its twelve hours of battery life did not disappoint.

Andrew Mitsi


The screen was particularly good. It is bright and visible from most angles, however heat is an issue, particularly around the Windows button on the front, and on the back where the battery housing is located.

Simon Harriott


My first impression after unboxing the Q702 is that it is a nice looking unit. Styling is somewhat minimalist but very effective. The tablet part, once detached, has a nice weight, and no buttons or switches are located in awkward or intrusive positions.


Latest Jobs

Don’t have an account? Sign up here

Don't have an account? Sign up now

Forgot password?