3

We have a lot of messages in the mail queue from a certain address. I want to delete the lot of them. I've found ways to delete by subject line, but I want to search by From address, and that seems to be a lot trickier. (Note: these are mainly outgoing messages.)

Some Googling has found me this command on HowToForge, but there's no explanation of what it does.

postqueue -p | tail -n +2 | awk 'BEGIN { RS = "" } / spammer@example\.net/ { print $1 }' | tr -d '*!' | postsuper -d - 

I was trying to use mailqueuemng, but didn't get very far (it doesn't have a --help, for one thing).

2
  • Are you using Postfix or qmail (or something else such as Exim)? You have tagged the question as qmail but the command snippet you included is for Postfix. – Ladadadada Jul 22 '13 at 21:00
  • Sorry, @Ladadadada. It is actually Postfix. I got confused, because we appear to also have qmail installed, and I believe the e-mail files themselves are stored in a directory called qmail. – TRiG Jul 22 '13 at 21:12
6

The pipeline can be analyzed step by step to see what it does. Try running each command in sequence until you understand them all:

postqueue -p

print the queue

postqueue -p | tail -n +2 

get rid of the first couple lines

postqueue -p | tail -n +2 | awk 'BEGIN { RS = "" } / spammer@example\.net/ { print $1 }' 

search for any lines with spammer@example.net; print the first field of those lines.

postqueue -p | tail -n +2 | awk 'BEGIN { RS = "" } / spammer@example\.net/ { print $1 }' | tr -d '*!'

get rid of any *!

This will output a bunch of queue ids.

postqueue -p | tail -n +2 | awk 'BEGIN { RS = "" } / spammer@example\.net/ { print $1 }' | tr -d '*!' | postsuper -d -

The final command tells postfix to delete those queue ids.

Read The Fine Man pages on postqueue, tail, tr, and postsuper. Awk is a more complicated, it's its own little language. you'll need a bit more than a man page to understand its complexity, although in my experience 99% of the awk usage is much like that particular one-liner.

2

Sorry to add an answer to an already answered question.

This is for people who have to do this on a daily basis (clients facing spam campaigns).

There's a guy who wrote "pymailq", a tool that can help dealing with this.

I've also forked this tool and added compatibility with zimbra and a few additional features.

Here's the original repo

Here's my fork

Installation goes like this:

git clone https://github.com/moebiuseye/pymailq.git
cd pymailq
git checkout dev

virtualenv venv
source venv/bin/activate

python ./setup.py install
pqshell

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.