Script to remove/delete mail from mail queue

Step: 01 

vi /root/removemail


#!/usr/bin/perl

$REGEXP = shift || die "no email-adress given (regexp-style, e.g. bl.*\@yahoo.co                                m)!";

@data = qx</opt/zimbra/common/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,"|/opt/zimbra/common/sbin/postsuper -d -") || die "couldn't open postsuper" ;

foreach (keys %Q) {

  print POSTSUPER "$_\n";

};

close(POSTSUPER);




Step: 02
chmod +x /root/removemail


Step: 03
/root/removemail spam@domain.com

Comments

Popular posts from this blog

Cambium cnPilot E400/E410/E500 Configuration Tutorial

Disabling Zimbra's AntiSpam, Amavis and AntiVirus filtering

Error "Unable to retrive Zimbra GPG key for package validation"