Cheap VPS & Xen Server

Residential Proxy Network - Hourly & Monthly Packages

DSPAM With Embedded ClamAV Integrated Into Postfix With Virtual Users And Domains

This document describes how to integrate DSPAM with embedded ClamAV into a mail server based on Postfix featuring virtual users and domains, i.e. users and domains that are in a MySQL database. It rests upon parts of the howto Virtual Users And Domains With Postfix, Courier And MySQL (Debian Etch) from Falko Timme.

The resulting Postfix server is functionally almost identic with the one from the howto above mentioned, but doesn’t need Amavisd.

This howto is meant as a practical guide; it does not cover the theoretical backgrounds. They are treated in a lot of other documents in the web.

This document comes without warranty of any kind! I want to say that this is not the only way of setting up such a system. There are many ways of achieving this goal but this is the way I take. I do not issue any guarantee that this will work for you!


1 Preparation

Please follow the howto Virtual Users And Domains With Postfix, Courier And MySQL (Debian Etch) from Falko Timme from Step 1 – 8 before you proceed.


2 Add The debian-volatile Repository

We add the debian-volatile repository to the sources.list, to get a newer version of ClamAV than the one in the debian repository.

vi /etc/apt/sources.list

It should look like this:

# deb cdrom:[Debian GNU/Linux 4.0 r0 _Etch_ - Official i386 NETINST Binary-1 20070407-11:29]/ etch contrib main
deb etch main
deb-src etch main
deb etch/updates main contrib
deb-src etch/updates main contrib
# Debian Volatile
deb etch/volatile main contrib non-free

Import the key for the debian-volatile repository:

wget -O- | apt-key add –

Now we refresh apt and update the system:

apt-get update && apt-get upgrade


3 Install DSPAM

apt-get install dspam dspam-doc libdspam7-drv-mysql

When you are asked to configure the database for libdspam7-drv-mysql with dbconfig-common, choose yes.

When you are asked for the database’s administrative user’s password, insert the one you chose in the howto before at step 4.

When you are asked for a password for libdspam7-drv-mysql, leave the field blank and choose OK. A password will be generated automatically.

4 Configure DSPAM

Now we have to edit the dspam.conf to our needs:

vi /etc/dspam/dspam.conf

Change the existing lines, that they look like this:

StorageDriver /usr/lib/dspam/
DeliveryPort 10026
DeliveryIdent localhost
DeliveryProto SMTP
Preference "spamSubject=SPAM"
Opt out
TrackSources spam virus
ParseToHeaders on
ChangeModeOnParse on
ChangeUserOnParse off
ServerPID /var/run/
ServerMode auto
ServerPass.Relay1 "secret"
ServerParameters "--deliver=innocent"
ServerIdent "localhost.localdomain"
ServerDomainSocketPath "/var/spool/postfix/var/run/dspam.sock"
ClientHost /var/spool/postfix/var/run/dspam.sock
ClientIdent "secret@Relay1"

Enable this configuration for all users:

vi /var/spool/dspam/group

It should look like this:


Go sure that you replace with a valid FQDN, otherwise your Postfix might not work properly!

Enable DSPAM:

vi /etc/default/dspam

Change START=no to START=yes

Start DSPAM:

/etc/init.d/dspam start

5 Configure Postfix

Now we integrate DSPAM into Postfix:

vi /etc/postfix/


smtp inet	n	-	-	-	-	smtpd


smtp inet	n	-	-	-	-	smtpd
     -o content_filter=lmtp:unix:/var/run/dspam.sock

After DSPAM has checked the mails, it will send it back to postfix. So we need to
configure Postfix for reinjection, without sending a checked mail again to DSPAM.

Add the following content:	inet	n	-	-	-	-	smtpd
		-o content_filter=
		-o receive_override_options=no_unknown_recipient_checks,no_header_body_checks
		-o smtpd_helo_restrictions=
		-o smtpd_client_restrictions=
		-o smtpd_sender_restrictions=
		-o smtpd_recipient_restrictions=permit_mynetworks,reject
		-o mynetworks=
		-o smtpd_authorized_xforward_hosts=

Restart Postfix:

/etc/init.d/postfix restart

Now we test if Postfix is working correctly:

telnet localhost 25

Should look like this:

Connected to localhost.localdomain.
Escape character is ‘^]’.
220 ESMTP Postfix (Debian/GNU)

ehlo localhost

Should look like this:
250-SIZE 10240000
250 DSN

Quit telnet:



6 Create First Mailaccount

If you are asked for the mysql-root-password, insert the one you chose in the howto before at step 4.

mysql -u root -p
USE mail;

INSERT INTO `domains` (`domain`) VALUES (‘’);
INSERT INTO `users` (`email`, `password`, `quota`) VALUES (‘’, ENCRYPT(‘userpassword’), 10485760);

Now the mail-account should be ready to use.
Postfix will automatically create the Maildirs when the first mail arrives to this account. So before you can get mails, you have to send one first to this account.

Recognized Spam will be marked with “SPAM” in the subject. To be sure that DSPAM has processed your mails, all mails will have an entry at the bottom like “!DSPAM:46b904f4169391516232331!”.


7 Train DSPAM

It would be useful to train DSPAM with spam and no-spam for better spam-detection.

Install bzip2:

apt-get install bzip2

Get train-mails:

cd /tmp

tar xvfj 20050311_spam_2.tar.bz2
tar xvfj 20030228_easy_ham_2.tar.bz2

Train DSPAM:

dspam_train test spam_2/ easy_ham_2/

DSPAM will now process the files (this will take a while) and fill the database with the resulting tokens.


8 Install And Configure ClamAV

apt-get install clamav-daemon

Change the configuration:

vi /etc/clamav/clamd.conf

Comment out “LocalSocket /var/run/clamav/clamd.ctl” (with a #) and add the new line:

TCPSocket	3310

Restart ClamAV:

/etc/init.d/clamav-daemon restart


9 Integrate ClamAV Into DSPAM

vi /etc/dspam/dspam.conf

Change the existing lines so that they look like this:

ClamAVPort     3310
ClamAVResponse reject

Restart DSPAM:

/etc/init.d/dspam restart


  • Virtual Users And Domains With Postfix, Courier And MySQL (Debian Etch)
  • The DSPAM Project:
  • ClamAV: