Copying email with qmail and Plesk

Posted by Greg on Server Fault See other posts from Server Fault or by Greg
Published on 2010-04-19T15:04:20Z Indexed on 2010/04/19 15:13 UTC
Read the original article Hit count: 436

Filed under:
|
|

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

incoming.sh

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

# $1 = context (/xxx/incoming)
# $3 = recipient ([email protected])
# Create /xxx/incoming/[email protected]
mkdir -p $1$3
# Save the email to /xxx/incoming/[email protected]/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?

© Server Fault or respective owner

Related posts about qmail

Related posts about plesk