Take the 2-minute tour ×
Server Fault is a question and answer site for professional system and network administrators. It's 100% free, no registration required.

I need to keep a copy of all outgoing and incoming email (for a single domain if possible) using qmail or Plesk. I can't recompile qmail, so qmailtap is out of the question, as is setting QUEUE_EXTRA in extra.h.

I'm pretty sure it should be possible with Plesk's mailmng utility, aka Mail Handlers but I'm having trouble getting them to work.

I've registered 2 hooks:

incoming hook

./mailmng --add-handler --handler-name=incoming --recipient-domain=example.com
    --executable=/xxx/incoming.sh --context=/xxx/incoming/ --hook=before-local


# The email is passed on stdin - grab it to a variable
e=`cat -`

# $1 = context (/xxx/incoming)
# $3 = recipient (test@example.com)
# Create /xxx/incoming/test@example.com
mkdir -p $1$3
# Save the email to /xxx/incoming/test@example.com/0123456789.txt
echo "$e" > $1$3/`date +%s%N`.txt

# Echo PASS to stderr
echo 'PASS' >&2

# Echo the email to stdout
echo "$e"

outgoing hook

# ./mailmng --add-handler --handler-name=outgoing --sender-domain=holidaysplease.com --executable=/xxx/outgoing.sh --context=/xxx/outgoing/ --hook=before-remote

The outgoing.sh file is the same as incoming.sh, except replace $3 (recipient) with $2 (sender).

The incoming hook does work, but saves 2 copies of each email - one before and one after SpamAssassin has run. The outgoing hook doesn't seem to get called at all.

So finally, my questions are:

  1. How can I make the incoming hook save only a single copy (preferably after SpamAssassin has run)?
  2. How can I get the outgoing hook to work?
share|improve this question

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

Browse other questions tagged or ask your own question.