Jump to content

Featured Replies

Posted
comment_63

This is short tutorial for clearing and deleting 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:

mailq


To remove all mail from the queue:

postsuper -d ALL


To remove all mails in the deferred queue:

postsuper -d ALL deferred

EXTRA

To delete or remove maildrop queues run this command

find /var/spool/postfix/maildrop/ -type f | xargs rm  -rf

SCRIPT :

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 :

#!/usr/bin/perl
 
$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";
};
close(POSTSUPER);


example usage of script :

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

 

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now