Have you have ever had a script or application accidentally send thousands of messages through your postfix queue? With this simple tip you no longer need to wait for those messages to be processed through the Postfix queue. This one liner is also helpful if you have a lot of differed messages in the Postfix queue you would like to discard.
You can simply use standard linux tools to awk through your Postfix queue and drop those unwanted messages. You will need access to
postsuper to list the queue and drop the unwanted messages from postfix.
Dropping Messages To/From a Specific Address
The usual caution: This will permanently drop the filtered messages from you postfix queue. You may want to see the output before piping it to postsuper.
sudo postqueue -p | grep 'firstname.lastname@example.org' | cut -d ' ' -f1 | tr -d '*' | sudo postsuper -d -
- List all of the messages that are currently in the postfix queue with
- Pipe the output to
tail -n +2skipping the first 2 lines of output.
- Next, pipe the output to
awkwhich looks for the address “email@example.com”.
trthen removes both “*” and “!” from the awk’d output.
postsuper -d -drops the message from the queue by using the message id.