How can I delete all messages from a certain address from the mailqueue?

Solution 1:

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 [email protected]; 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.

Solution 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

Tags:

Email

Postfix