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:
To see the Postfix mail queue, simply enter:
To delete all mail from the Postfix mail queue:
postsuper -d ALL
To remove all mails in the deferred queue:
postsuper -d ALL deferred
Remove all mails in the hold queue:
postsuper -d ALL hold
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>
Or release all hold mails from the hold queue:
postsuper -H ALL
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 hold
Everything can be put together in a management Bash script. One example is to delete all MAILER-DAEMON mails from the queue in Postfix.
# 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 -k6n
How to flush postfix mail queue, delete all mail, and its various operations.
If you want to step in to help me cover the costs for running this website, that would be awesome. Just use this link to donate a cup of coffee ($5 USD for example). And please share the love and help others make use of this website. Thank you very much!
My name is Jan. I am not a hacker, coder, developer, programmer or guru. I am merely a system administrator, doing my daily thing at Vevida in the Netherlands. With over 15 years of experience, my specialties include Windows Server, IIS, Linux (CentOS, Debian), security, PHP, websites & optimization.
Restore single MySQL table from a full mysqldump backup file
Benchmarking WordPress, simple load & speed testing with ApacheBench
Recursive scp and symlinks
Generate pseudo-random passwords with OpenSSL
Tunnel RDP through SSH & PuTTY
Turn off swap