I have a mailq which is getting backed up with multiple emails with the same subject line. I would like to delete all emails in the mailq that match a particular subject line so they don't get sent. Any ideas how to do this? Pretty urgent as its spam related.
With a typical postfix installation the email will be in /var/spool/postfix. There are several queues. You want to stop postfix so that you can safely use postsuper to remove the emails. This short script will remove all the emails that match a particular string. In our case we needed to find thousands of emails that all had the same subject line.
In this case, the emails were all deferred, because our remailing service had rejected them due to our being over the limit.
Some key notes on this:
Hope this helps people who find this and are looking for more specific instructions.
Postfix does not have a utility like exigrep, so you will need to grep the queue files for the subject and then pipe the queue id to postsuper to delete them
Just an alternative command to do the same proposed by gview:
Nowadays, postqueue can output structured json with -j.
You can extract required info using simple grep or a json parser in your favorite language.
eg extract queue id and email with sed:
you can continue it like:
egrep to filter desired addresses, cut to get the first field, and postsuper -d - to remove all queue ID's received from the pipe. You can create an alias for a lightweight solution or of course use python / perl / whatever to build your sophisticated solution.
You can use: