CentosControl PanelLinuxUbuntu

How to Flush/Clear/Delete Postfix Mail Queue

This is short tutorial for clearing the mail queue from command line. Postfix is the mail server which is used to send mails, time to time there will increase in mail queue which contains failed email in order to check and clear the mail queue just run this following command from terminal/ssh.

To check mail queue:


To remove all mail from the queue:

postsuper -d ALL

To remove all mails in the deferred queue:

postsuper -d ALL deferred

Also you can use this script to delete mail queue which contain certain keyword or email id :

cd /root
touch mailq-del.pl
chmod 775 mailq-del.pl
nano mailq-del.pl

and add this below code in mailq-del.pl and save it :

$REGEXP = shift || die "no email-adress given (regexp-style, e.g. bl.*\@gmail.com)!";
@data = qx</usr/sbin/postqueue -p>;
for (@data) {
  if (/^(\w+)(\*|\!)?\s/) {
     $queue_id = $1;
  if($queue_id) {
    if (/$REGEXP/i) {
      $Q{$queue_id} = 1;
      $queue_id = "";
#open(POSTSUPER,"|cat") || die "couldn't open postsuper" ;
open(POSTSUPER,"|postsuper -d -") || die "couldn't open postsuper" ;
foreach (keys %Q) {
  print POSTSUPER "$_\n";

example usage of script :

cd /root
./mailq-del.pl example@gmail.com
./mailq-del.pl keyword

Sandeep B.

I'm a system admin and php developer and currently working as System Admin In CWP Control panel, expertise in Linux and Windows administration RHEL certified admin.

Related Articles


  1. Is it possible to tweak the deferred scan times. I had only 2 email in the deferred queue and they are still there for 7 hours.

  2. Why vestacp is faster than CWP for deliver emails?
    I also tested in fresh install.
    Usually, CWP delivers emails after 30-32 seconds but vestacp delivers emails after 1-3 seconds.

    1. Hi jack i tested both vestacp (exim) and cwp (postfix) mail server and it seems to be both faster and delivers mails instantly.

      try to check if you’ve lots of mail queue in CWP (postfix) cleaning the mail queue will improve faster mail delivery actions and also sometime delay happens because of mail server bruteforce /ddos attacks specially when you’ve amavisd enabled try to use only mail server without security under CWP.

Leave a Reply

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

Back to top button