Release hold queue email in Postfix – postsuper

How to flush Postfix’ mail queue from the command line and delete all mail from the queue? Easy, use the Postfix postsuper command as explained in this post. The postsuper command controls different types of queues in the Postfix mail system, like the deferred or hold queue. This post shows you some Postfix queue operations to maintain your mail servers.

The Postfix superintendent postsuper command does maintenance jobs on the Postfix queue. Use of the command is restricted to the superuser. The following commands releases or deletes mail:

Postfix logo
Postfix logo

To see the Postfix mail queue, simply enter the following command on your Linux Bash shell:

mailqCode language: Bash (bash)

To delete all mail from the Postfix mail queue:

postsuper -d ALLCode language: Bash (bash)

To remove all mails in the deferred queue:

postsuper -d ALL deferredCode language: Bash (bash)

Remove all mails in the hold queue:

postsuper -d ALL holdCode language: Bash (bash)

You can use -H to release an email that was put “on hold” in Postfix’ queues. Release an email by its queue-id:

postsuper -H <queue_id>Code language: Bash (bash)

Or release all hold mails from the hold queue:

postsuper -H ALLCode language: Bash (bash)

Are you running multiple Postfix mail instances? Use postmulti, the multi-instance manager:

postmulti -i <instance> -x mailq
postmulti -i <instance> -x postsuper -d ALL
postmulti -i <instance> -x postsuper -d ALL deferred
postmulti -i <instance> -x postsuper -d ALL holdCode language: Bash (bash)

Sort Postfix’ mailq by date

It is always nice to sort mailq’s output by date. @climagic posted on Twitter:

# Show your postfix mail queue sender/queueid lines and order them by time 
# (day and hour at least)
mailq |grep "^[A-F0-9]" |sort -k5n -k6n

# or add -r to sort to reverse the date sort output (may not always be correct)
mailq |grep "^[A-F0-9]" |sort -k5rn -k6nCode language: Bash (bash)

Display email subject in Postfix queue

If you want to show the subject line of an email in Postfix’ queue, you can use this:

# deferred queue
mailq | grep -v [\!\*] | grep ^[0-9A-Z] | cut -d " " -f 1 | xargs postcat -qh | grep ^Subject
# hold queue
mailq | grep \! | grep ^[0-9A-Z] | cut -d '!' -f 1 | xargs postcat -qh | grep ^SubjectCode language: 1C:Enterprise (v7, v8) (1c)

Jan Reilink

Hi, my name is Jan. I am not a hacker, coder, developer or guru. I am merely an application manager / systems administrator, doing my daily thing at Embrace - The Human Cloud. In the past I worked for clidn and Vevida. With over 20 years of experience, my specialties include Windows Server, IIS, Linux (CentOS, Debian), security, PHP, websites & optimization. I blog at https://www.saotn.org.