/usr/sbin/postqueue -p
/usr/sbin/postcat -q 7959BB854D
/usr/sbin/postsuper -d 7959BB854D
Postfix Queue Management
Queue’s
Postfix utilizes several queue’s below you can find a brief description of each queue and it’s function.
Incoming
This is Postfix’s main queue, once a message has entered the system through the appropriate channels it will will then be evaluated by the cleanup service. This services is responsible for fixing missing headers and content evaluation before email is actually queued. When sending messages from the incoming queue to the active queue resource limits are checked to make sure no limits will be exceeded.
Active
This queue is fairly similar to the incoming queue. However this queue is different than any other in the way that this queue is stored within memory, therefore the queue is limited to 20.000 messages by default. When this limit is exceeded the queue manager will stop scanning for incoming and deferred messages. Messages within this queue are ready to be delivered to the intended recipients.
Maildrop
Used by Sendmail, messages in this queue will be handled by the pickup service which it will scan on regular basis.
Deferred
If Posfix cannot deliver a message to the intended recipient the messages is placed into the ‘deferred’ queue. The queue manager will scan the queue and see if it can move it’s messages back to the active queue. How often this happens is defined by the ‘queue_run_delay’. On busy mail servers the mail queue might be quite large, while flushing this queue might seem to be a good idea it’s actually counter productive. The only valid reason for flushing the ‘deferred’ queue is if you are certain messages have a good change of delivery. (eg; changed acl/route).
Hold
This queue is there for convenience, while Postfix itself does not directly uses it you can tell it to using the ‘header_checks’ and ‘body_checks’. An other valid reason for using this queue is if you want to move suspicious messages away from the queue’s where Postfix will try to deliver them. Messages will remain in this queue until they expire the maximal lifetime set by ‘maximal_queue_lifetime’ and are bounced back to the original sender.
Corrupt
Queue files that became corrupted are placed into this queue directory. Using the postcat command messages can be previewed.
Commands
postqueue -p: list current mail-queue.
postqueue -i <message_id>: schedule immediate delivery of message.
postsuper -d <message_id>: remove message from queue.
postsuper -h <message_id>: move message into hold queue.
postsuper -r <message_id>: re-queue message to incoming/active.
Each of the above postsuper commands the message_id field is optional. However take into account that if no message_id is specified it will default to ALL, potentially deleting everything in all queues. To delete all messages in the hold queue one could execute; postsuper -d ALL hold. An other great thing about postsuper is that it can read it’s message_id’s from stdin, the only thing you have to a append is a dash(-)[eg; postsuper -d – to listen to stdin].
‘*’ means message is in the active queue and delivery attempts are made.
‘!’ means that the message is within the hold queue.
Example
To cleanup unsolicited messages from the mail-queue one could follow the following steps;
Execute postsuper -h ALL hold.
This will move all messages to the hold queue.
The Incoming/Active queue should now be able to store legitimate email.
Fix the actual issue, blacklist host/reconfigure Postfix.
Now cleanup the hold queue.
Delete all messages you do not want to deliver. postqueue -p, postcat -q <message_id> and postsuper -d <message_id> are your friends here.
Re-queue the remaining legitimate email to the active queue.
#!/usr/bin/perl -w
use strict;
my $postqueue = “/opt/zimbra/postfix/sbin/postqueue -p”;
my $postsuper = “/opt/zimbra/postfix/sbin/postsuper”;
my $email_address = “mark.kerssens\@t-mobile.nl”;
my $queue_id = “”;
open(QUEUE,”$postqueue |”) || die “Could not open file-handle for postqueue: $!\n”;
my $line =<QUEUE>;
$/ = “”;
while ($line = <QUEUE>){
if($line =~ / ($email_address)$/m){
($queue_id) = split(/\s+/, $line, 2);
$queue_id =~ s/[\*\!]//;
next unless ($queue_id);
if(system($postsuper, “-h”, $queue_id)!=0){
die “Something failed during the execution of postsuper, perhaps you forgot to use sudo?\n”;
}
}
}
close(QUEUE);
if(!$queue_id){
die “No message in queue found for <$email_address>\n”;
}
exit 0;