How to delete e-mails from Zimbra’s MTA Postfix Queue

Sometimes you will end up on a situation where you need to delete a lot of e-mails that got stuck on your Postfix’s queue (SPAM issues, most probably). Here are the steps when using Zimbra.
For deleting e-mails from a specific sender, we will launch mailq, grep for the domain or sender’s address and then feed through postsuper with:
/opt/zimbra/postfix/sbin/mailq | tail -n +2 |
grep -v ‘^ *(‘ | awk ‘BEGIN { RS = “” } { if ($8 ~ /@domain.com/) print $1 }’ | tr -d ‘*!’ |
/opt/zimbra/postfix/sbin/postsuper -d –
For deleting all e-mails from the queue:
/opt/zimbra/postfix/sbin/postsuper -d ALL
All commands should be run as root.

For 8.8


commands :

#####To delete single mail id’s queue– zimbra 8.8#############
/opt/zimbra/common/sbin/postqueue -p | tail -n +2 | awk ‘BEGIN { RS = “” } / [email protected]/ { print $1 }’ | tr -d ‘*’ | /opt/zimbra/common/sbin/postsuper -d –
###################################################################

########## To delete mailqueue of domain-zimbra 8.8###########
/opt/zimbra/common/sbin/postqueue -p | tail -n +2 | awk ‘BEGIN { RS = “” } / *inc5shoes.com/ { print $1 }’ | tr -d ‘*’ | /opt/zimbra/common/sbin/postsuper -d –
################################################################

Zimbra delete mail queue 8.6

/opt/zimbra/postfix/sbin/postqueue -p | tail -n +2 | awk 'BEGIN { RS = "" } / [email protected]/ { print $1 }' | tr -d '*' | /opt/zimbra/postfix/sbin/postsuper -d -

********************************************************************************************************

How to review the email message your server is trying to send.
There are two queues within Postfix: pending and differed. The pending queue includes all messages that have been submitted to postfix which have not yet been sent out and handed off to the recipient server. The differed mail queue holds all messages that have soft-failed and need to be retired (temporary failure). Postfix will retry sending the deferred queue on set intervals (this is configurable, but is set to 5 minutes as a default).
The following commands will allow you to review these queues:
1- Display the mail queues, deferred and pending
mailq
or
postqueue -p
To save the output to a text file you can run:
mailq > mailqueue.txt
or
postqueue -p > mailqueue.txt
Either of these commands will show you all queued messages.
NB: this command shows the sender and recipients and ID, not the message itself. The ID is particularly useful if you want to inspect the message itself.
2- View message (contents, header and body) in Postfix queue
To view a message with the ID XXXXXXX
(you can see the ID from the queue)
postcat -vq XXXXXXXXXX
for 8.6 zimbra
go to folder /opt/zimbra/postfix/sbin
and for 8.8.11 zimbra
goto /opt/zimbra/common/sbin

and run the command as a root user

postcat -vq XXXXXXXXXX

Or to save it in a file

postcat -vq XXXXXXXXXX > emailXXXXXXXXXX.txt
A useful feature for web servers is to enable mail.add_x_header = on in the Postfix configuration. This will add a header to all outgoing email messages showing the script and user that generated each message.  Once enabled this will then add the following extra header to message:
X-PHP-Originating-Script: 1001:spamEmailer.php
In this example 1001 is the UID and the spamEmailer.php was the script sending the message. This can allow you to quickly track down the source of spam messages being sent by your server.
With these commands you should be able to review your mail queue and make sure that intended messages are being sent and have not been rejected.
How to delete queued mail from the mail queue
Now that we have learned the necessary steps to reviewing your mail queue, the final 3 tips will demonstrate how to delete queued mail.
3- Tell Postfix to process the queue now
postqueue -f
OR
postfix flush
This will cause Postfix to immediately attempt to send all queued messages.
4- Delete queued mail
Delete all queued mail
postsuper -d ALL
Delete only the differed mail queue messages (i.e. only the ones the system intends to retry later)
postsuper -d ALL deferred
5- Delete mail from the queue selectively
This is not something that is natively included with the standard Postfix tools however can be done with a bit of Perl scripting.
NB: This perl script seems to be free, and is all over the internet however I could not find out where it originates or who wrote it but my thanks go to them!
#########################################
#!/usr/bin/perl
$REGEXP = shift || die “no email-adress given (regexp-style, e.g. bl.*@yahoo.com)!”;
@data = qx;
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);
#########################################
Usage Examples:
Delete all queued messages to or from the domain called spamers.com, enter:
./postfix-delete.pl spamers.com
Delete all queued messages that contain the word “spam” in the e-mail address:
./postfix-delete.pl spam
If you’re having trouble with your mail server, and this hasn’t helped you fix things why not

Leave a Comment

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

To Resolve this issue at just 5$ from ServerExpert

https://serverexpert.io/

For Hosting please visit Hostingwebsite.io

You have Successfully Subscribed!

Open chat