What`s that?

qmail-spp adds plugin support to qmail`s SMTP daemon (qmail-smtpd). It`s written entirely in C using native qmail libraries, so it does not create any dependencies.

Why should I use it?

qmail-spp has been written because currently there is no common way of enhancing qmail-smtpd`s functionality apart of patches which usually are not compatible one with other and require recompilation. In addition, qmail-spp gives you possibility of enhancing your mail server in any language, so you can easily integrate it with anything you want.

How does it work?

Plugins are external programs which are executed after processing SMTP command, but just before accepting it by qmail - this lets you to add extra checks on commands` arguments before accepting it - for instance you can check envelope recipient address against your "black list".

Plugins can be written in any language, because they are independent programs. They:

All required data (as HELO host, last RCPT address, etc.) can be retrieved from environmental variables.

Which SMTP commands can be enhanced this way?

HELO/EHLO, MAIL, RCPT, DATA and (if supported) AUTH. There is also one pseudo-event triggered just after client connection.

Regarding DATA: you can't run plugins which filter message content, you can only do something else than standard 354 go ahead - this may be useful for e.g. greylisting.

What environmental variables are set by qmail-spp?

SMTPHELOHOSTargument of 'HELO/EHLO' command
SMTPMAILFROMargument of 'MAIL' command
SMTPRCPTTOargument of last 'RCPT' command
SMTPRCPTCOUNThow many times has 'RCPT' command been accepted
SMTPRCPTCOUNTALLas above, but counts all issued 'RCPT' commands
SMTPRCPTHOSTSOKrcpthosts check was successful (1) or not (0)

Remark for SMTPRCPTCOUNT* variables: SMTPRCPTCOUNT is incremented after accepting the recipient by your plugin, and SMTPRCPTCOUNTALL is incremented before asking the plugin if the recipient should be accepted. This means that usually you will observe SMTPRCPTCOUNT=0 and SMTPRCPTCOUNTALL=1 in your plugin after first RCPT command.

And if SMTP AUTH is supported:

SMTPAUTHUSERuser name of authorized SMTP client
SMTPAUTHMETHODused SMTP authorization method

You should probably also take a look at if you use tcpserver (from ucspi-tcp package).

What environmental variables can I use to control qmail-spp?

NOSPPif set, qmail-spp won't run in this session
SPPCONFFILEif set, specifies alternative configuration file (instead of standard "control/smtpplugins")

What plugin commands are supported and how to use them?

Aaccept mail - turn off qmail-spp in this session
Nnext - accept current SMTP command (do not execute remaining plugins for this command)
Ook - like N, but omits qmail checks in MAIL and RCPT
Emsgerror - do not accept this SMTP command and immediately send msg to the client
LMmsglater, mail - like E, but shows error after MAIL command
LRmsglater, rcpt - like E, but shows error after RCPT command
LDmsglater, data - like E, but shows error after DATA command
Rmsgreject mail - send msg to the client and drop connection
Ddrop connection immediately, without printing anything
Svar=valueset environmental variable var to value
Uvarunset var variable
Hcontentheader - add header content (eg. X-Spam-Flag: YES)
Cfoo@bar.comchange last address provided by the client to (MAIL FROM or RCPT TO address)
Pmsgprint - send msg to the client

Plugins should simply print commands on standard output, one per line, eg. RCPT plugin which prints:

to standard output:
HX-Spam-Flag: YES

to standard error:

redirected spam from <$SMTPMAILFROM>




Simply cd into the qmail source dir, patch it and install in usual way.

Following patches are bundled with qmail-spp:

Remember to create configuration file (see below) - you can also use sample smtpplugins file bundled in samples/ directory.


The main default configuration file of qmail-spp is


file (assuming that /var/qmail is your qmail home dir).

It consist of few sections, one for each command:

Section names are marked using square brackets ('[' and ']'). After section name there are plugins to execute for this command - one per line.


# smtpplugins sample file
:plugins/rbl -r






Paths are relative to the qmail home dir (usually /var/qmail).

Note: If you want your plugin to be executed by system shell (/bin/sh -c), add a colon (':') before the plugin path. This might be useful for debugging or passing arguments to your program, but note that this is slightly slower than normal mode.

Copyright © 2004-2008 Paweł Foremski

Permission is granted to copy, distribute and/or modify this document under the terms of the GNU Free Documentation License, Version 1.2 or any later version published by the Free Software Foundation; with no Invariant Sections, no Front-Cover Texts, and no Back-Cover Texts. A copy of the license can be found here.