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 (www.spamassassin.org), 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 < spam.txt

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.

KMail

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

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 newsletter!

Or

Sign up to gain exclusive access to email subscriptions, event invitations, competitions, giveaways, and much more.

Membership is free, and your security and privacy remain protected. View our privacy policy before signing up.

Error: Please check your email address.
Keep up with the latest tech news, reviews and previews by subscribing to the Good Gear Guide newsletter.

Alastair Cousins

PC World
Show Comments

Father’s Day Gift Guide

Brand Post

Most Popular Reviews

Latest Articles

Resources

PCW Evaluation Team

Luke Hill

MSI GT75 TITAN

I need power and lots of it. As a Front End Web developer anything less just won’t cut it which is why the MSI GT75 is an outstanding laptop for me. It’s a sleek and futuristic looking, high quality, beast that has a touch of sci-fi flare about it.

Emily Tyson

MSI GE63 Raider

If you’re looking to invest in your next work horse laptop for work or home use, you can’t go wrong with the MSI GE63.

Laura Johnston

MSI GS65 Stealth Thin

If you can afford the price tag, it is well worth the money. It out performs any other laptop I have tried for gaming, and the transportable design and incredible display also make it ideal for work.

Andrew Teoh

Brother MFC-L9570CDW Multifunction Printer

Touch screen visibility and operation was great and easy to navigate. Each menu and sub-menu was in an understandable order and category

Louise Coady

Brother MFC-L9570CDW Multifunction Printer

The printer was convenient, produced clear and vibrant images and was very easy to use

Edwina Hargreaves

WD My Cloud Home

I would recommend this device for families and small businesses who want one safe place to store all their important digital content and a way to easily share it with friends, family, business partners, or customers.

Featured Content

Product Launch Showcase

Don’t have an account? Sign up here

Don't have an account? Sign up now

Forgot password?