Skip to main content

Postfix Message Queue: Delete messages from a specific sender and to a specific recipient

I arrived this morning to a Postfix mail queue with more than 14,000 messages queued up. After inspecting the queue with

postqueue -p

I found that most of the messages were from a single spammer to a specific user. In order to clear the queue of these spam messages, I found the following bash script to delete all messages from a single sender to a single user:

mailq | tail -n +2 | head -n -2 | grep -v '^ *(' | awk 'BEGIN { RS = "" } { if (($7 == "<a href="mailto:sender@example.com">sender@example.com</a>") &amp;&amp; ($8 ~ "somedomain.com")) print $1 }' | tr -d '*!' | postsuper -d -

The original script came from here. Thank you for the assist.


Comments