fbpx

How to delete messages from the Postfix queue using the command line

Background

There are a multitude of methods that can be used to delete messages from the Postfix queue. This article summarizes a couple of them. Typically one would use the command line as it has the most powerful expressions that can be used to find that what you want deleted.

Important: During a time of postfix crisis it often makes sense to stop Postfix while you are working on it. The fact is sending 1000s of messages will damage your IP reputation or the sender’s system, and it will slow down the server computer. So seriously consider to do this first:

/etc/init.d/postfix stop

Method 1

Delete all email from a specific sender to a specific recipient address

The key to solving numerous complex system administration problems is to spot the pattern. If you’re in the fortunate situation where the pattern is to delete all email from [email protected] to [email protected], then use the snippet below:

mailq | tail -n +2 | head -n -2 | grep -v '^ *(' | awk 'BEGIN { RS = "" } { if (($7 == "[email protected]") && ($8 ~ "[email protected]")) print $1 }' | tr -d '*!' | postsuper -d -

Additional Methods

You can use Webmin or the command line to delete Postfix messages in the queue.

Typically you have to resort to this remedy when you’re Postfix system has been spammed.

Of course you want to also find the root cause of the breach but that’s another article and matter entirely.

Webmin might be slow, so rather use the command line.

To cut to the chase, the command you should use is:

postqueue -p | tail -n +2 | awk 'BEGIN { RS = "" } /vtext\.com/ { print $1 }' | tr -d '*!' | postsuper -d -

Replace the text between “/” and “/”, ie. replace vtext\.com with whatever probably FROM or TO address you want to remove.

It also works for MAILER-DAEMON which will be in the 100s or 1000s after a spamming incident:

postqueue -p | tail -n +2 | awk 'BEGIN { RS = "" } /MAILER-DAEMON/ { print $1 }' | tr -d '*!' | postsuper -d -

To delete all message in the queue,  do this:

postsuper -d ALL

References

Share this article

Share on facebook
Share on twitter
Share on linkedin

Leave a Reply

Your email address will not be published. Required fields are marked *

Scroll to Top