Click here to Skip to main content
15,126,367 members
Articles / Programming Languages / C#
Posted 18 Feb 2006


22 bookmarked

A C# Wrapper for the SpamAssassin Protocol

Rate me:
Please Sign up or sign in to vote.
4.69/5 (15 votes)
18 Feb 2006CPOL3 min read
Introducing a class that simplifies the communication with a SpamAssassin server

SpamAssassin logo


(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:

Deutschsprachiges Forum zu Elektromobilität und Tesla  
Windows 10 Ereignisanzeige  
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

Comments and Discussions

Question[Message Deleted] Pin
Z Kavtaskin25-Jun-09 0:28
MemberZ Kavtaskin25-Jun-09 0:28 
Uwe Keim25-Jun-09 0:36
sitebuilderUwe Keim25-Jun-09 0:36 
GeneralMessage Removed Pin
8-May-09 5:52
MemberZ Kavtaskin8-May-09 5:52 
GeneralAn existing connection was forcibily closed by the remote host Pin
Member 234143013-Oct-08 6:01
MemberMember 234143013-Oct-08 6:01 
QuestionWebservice down Pin
RafaMiranda20-Jul-06 11:00
MemberRafaMiranda20-Jul-06 11:00 
AnswerRe: Webservice down Pin
Uwe Keim20-Jul-06 19:11
sitebuilderUwe Keim20-Jul-06 19:11 
GeneralRe: Webservice down [modified] Pin
RafaMiranda21-Jul-06 5:23
MemberRafaMiranda21-Jul-06 5:23 
GeneralRe: Webservice down Pin
Uwe Keim21-Jul-06 5:37
sitebuilderUwe Keim21-Jul-06 5:37 
QuestionRe: Webservice down Pin
RafaMiranda25-Jul-06 11:45
MemberRafaMiranda25-Jul-06 11:45 
AnswerRe: Webservice down Pin
Uwe Keim25-Jul-06 18:41
sitebuilderUwe Keim25-Jul-06 18:41 
QuestionNo Spam? Pin
VicSmurf18-Apr-06 11:44
MemberVicSmurf18-Apr-06 11:44 
AnswerRe: No Spam? Pin
Uwe Keim19-Apr-06 8:13
sitebuilderUwe Keim19-Apr-06 8:13 
QuestionFormat Exception error Pin
206mph23-Mar-06 8:00
Member206mph23-Mar-06 8:00 
AnswerRe: Format Exception error Pin
Uwe Keim23-Mar-06 12:32
sitebuilderUwe Keim23-Mar-06 12:32 
QuestionWhy is it better? Pin
Super Lloyd18-Feb-06 18:06
MemberSuper Lloyd18-Feb-06 18:06 
AnswerRe: Why is it better? Pin
Uwe Keim18-Feb-06 18:27
sitebuilderUwe Keim18-Feb-06 18:27 
GeneralRe: Why is it better? Pin
Super Lloyd18-Feb-06 18:36
MemberSuper Lloyd18-Feb-06 18:36 
GeneralRe: Why is it better? Pin
Super Lloyd18-Feb-06 18:37
MemberSuper Lloyd18-Feb-06 18:37 
GeneralRe: Why is it better? Pin
Uwe Keim18-Feb-06 18:56
sitebuilderUwe Keim18-Feb-06 18: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.