How can I delete all messages from a certain address from the mailqueue?
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).
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.
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