Click here to Skip to main content
13,551,474 members
Click here to Skip to main content
Add your own
alternative version


22 bookmarked
Posted 18 Feb 2006
Licenced CPOL

A C# Wrapper for the SpamAssassin Protocol

, 18 Feb 2006
Rate this:
Please Sign up or sign in to vote.
Introducing a class that simplifies the communication with a SpamAssassin server
<!------------------------------- STEP 2 ---------------------------><!-- Include download and sample image information. -->

SpamAssassin logo

<!------------------------------- STEP 3 ---------------------------><!-- Add the article text. Please use simple formatting (


etc) -->


(This article is followed by my article "Using the ZetaSpamAssassin Wrapper in a real-word application")

SpamAssassin is an open source server application that checks (e-mail) messages for being spam or no spam. In this article I describe a class that enables you to easily communicate with a SpamAssassin server to check whether a given text (string) is likely to contain spam text.

Why I created the Wrapper

To our customers, we provide some ASP ("application service provider") applications like guestbooks and discussion boards, all hosted centralized on our servers. In the last month, customers increasingly complained about the lot of spam in their guestbooks and discussion boards.

The first solution that came to my mind was to implement a Captcha, which is well documented on CodeProject, too. Just search for it!

I even started implementing Captcha when a colleague of mine interrupted me and pointed to a better solution: Let the messages that are posted to those guestbooks and discussion boards be checked by a background application. He pointed me to the WordPress SpamAssassin Plugin, a PHP script for the popular Weblog application WordPress.

I used this WordPress plugin as a starting point for my own implementation. Basically it connects to a SpamAssassin server in the background, doing some socket communication to send a text to check and receive a response from the SpamAssassin server whether he thinks that the text is likely to be spam or not.

After doing some tests, I discovered the complete protocol specification (or some sort of) for SpamAssassin and wrote a class to encapsulate the protocol.

The SpamAssassin Protocol

SpamAssassin has several so called "Commands" to send from a client (called "SPAMC") to a SpamAssassin server (called "SPAMD" for "Demon"). Those commands are:

  • SKIP
  • PING
  • TELL

Please refer to the protocol specification for details about the single commands. Each command being sent from a SPAMC contains a different payload depending on the command. The result that is returned by SPAMD depends on the used command, too.

The SpamAssassin Protocol Wrapper

The class SpamAssassinProtocol wraps the SpamAssassin commands in an easy-to-use manner. For each command there are three elements:

  • A function to execute a command. E.g. SpamAssassinProtocol.ExecuteCheck() for executing the CHECK command.
  • A class that contains the parameters passed to the command function. E.g. SpamAssassinCheckArgs for passing the parameters for the CHECK command.
  • A class that contains the result returned from the command function. E.g. SpamAssassinCheckArgs for the result from the CHECK command.

The class currently contains the basic wrappers. Probably I do need to provide more abstract functions and classes to make the single commands being more usable in a real-word scenario.

A test application is included in the download at the top of this article.


In order to use this class in you own website you need the following requirements:

  • Microsoft .NET Framework 2.0
  • A running SpamAssassin server (Linux)

Please see my article "Using the ZetaSpamAssassin Wrapper in a real-word application" where I introduce a web service to you that could remove the needs for running a webservice by yourself.


In this article I shortly introduced you an easy-to-use class that encapsulates the SpamAssassin protocol for communicating from a SPAMC to a SPAMD.

Please note that I am rather "SpamAssassin-illiterate", knowing only the minimum about SpamAssassin that I needed to know in order to create the class. All the installation and configuration was did by my colleague Rainer. So it is likely that I missed some of the concepts that the SPAMD authors put into their commands.

I am therefore curious on feedback from you about the class and practial applications you created with it and how to improve it. Keep your comments coming! (simply use the comments section below)


  • 2006-02-18:
    First version of the article. The SpamAssassinProtocol class contains the basic wrappers and was initially tested for working functionality. More testing and adjustment will be required when more feedback from you comes in!
  • 2006-02-18:
    Please also see my article "Using the ZetaSpamAssassin Wrapper in a real-word application"


This article, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)


About the Author

Uwe Keim
Chief Technology Officer Zeta Producer Desktop CMS
Germany Germany
Uwe does programming since 1989 with experiences in Assembler, C++, MFC and lots of web- and database stuff and now uses ASP.NET and C# extensively, too. He has also teached programming to students at the local university.

In his free time, he does climbing, running and mountain biking. Recently he became a father of a cute boy.

Some cool, free software from us:

German Developer Community  
Free Test Management Software - Intuitive, competitive, Test Plans. Download now!  
Homepage erstellen - Intuitive, very easy to use. Download now!  
Send large Files online for free by Email

You may also be interested in...

Comments and Discussions

Question[Message Deleted] Pin
Member 472935824-Jun-09 23:28
memberMember 472935824-Jun-09 23:28 
Uwe Keim24-Jun-09 23:36
sitebuilderUwe Keim24-Jun-09 23:36 
Member 472935824-Jun-09 23:56
memberMember 472935824-Jun-09 23:56 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.

Permalink | Advertise | Privacy | Terms of Use | Mobile
Web02 | 2.8.180515.1 | Last Updated 18 Feb 2006
Article Copyright 2006 by Uwe Keim
Everything else Copyright © CodeProject, 1999-2018
Layout: fixed | fluid