Postfix queues and related information
Translation of the original in Catalan. Read it in: CatalàCastellano
By default the queues postfix has are:
-
hold: messages that are never attempted to be delivered
-
incoming: message input queue
-
active: queue in which it is decided with which delivery agent a message is attempted to be delivered
-
defer/deferred: messages that could not be delivered due to a temporary error are put in this queue
-
bounce: where the error messages are generated towards the sender of the messages that could not be delivered
-
corrupt: queue that contains damaged messages that nothing can be done with
Actions we can take with the messages in a queue:
-
Listing messages
-
Deleting messages
-
Holding messages
-
Requeuing messages
-
Displaying messages
-
Flushing messages
Queue management:
-
Shows the status of all the queues.
mailq
- Show the 10 domains with the most messages pending delivery, it is often handy to check when we have been used to send an email and there are many messages stuck waiting to be sent.
qshape -s deferred|head -n 10
- Delete a message from the queues.
postsuper -d ID_MSG
- Delete all the messages from the queues.
postsuper -d ALL
- Script to delete messages from the queues by origin or destination:
#!/usr/bin/perl -w
#
# pfdel - deletes message containing specified address from
# Postfix queue. Matches either sender or recipient address.
#
# Usage: pfdel <email_address>
#
use strict;
# Change these paths if necessary.
my $LISTQ = "/usr/sbin/postqueue -p";
my $POSTSUPER = "/usr/sbin/postsuper";
my $email_addr = "";
my $qid = "";
my $euid = $>;
if ( @ARGV != 1 ) {
die "Usage: pfdel <email_address>\n";
} else {
$email_addr = $ARGV[0];
}
if ( $euid != 0 ) {
die "You must be root to delete queue files.\n";
}
open(QUEUE, "$LISTQ |") ||
die "Can't get pipe to $LISTQ: $!\n";
my $entry = <QUEUE>; # skip single header line
$/ = ""; # Rest of queue entries print on
# multiple lines.
while ( $entry = <QUEUE> ) {
if ( $entry =~ / $email_addr$/m ) {
($qid) = split(/\s+/, $entry, 2);
$qid =~ s/[\*\!]//;
next unless ($qid);
#
# Execute postsuper -d with the queue id.
# postsuper provides feedback when it deletes
# messages. Let its output go through.
#
if ( system($POSTSUPER, "-d", $qid) != 0 ) {
# If postsuper has a problem, bail.
die "Error executing $POSTSUPER: error " .
"code " . ($?/256) . "\n";
}
}
}
close(QUEUE);
if (! $qid ) {
die "No messages with the address <$email_addr> " .
"found in queue.\n";
}
exit 0;
- Delete messages by sender or recipient email.
/root/bin/pfdel email
- Hold a message / Hold messages, do not attempt to serve them. Put them in a frozen queue.
postsuper -d ID_MSG
- Hold all messages
postsuper -d ALL
- Move a message from the 'hold' queue to the 'active' queue.
postsuper -H ID_MSG
- Move all the messages from the 'hold' queue to the 'active' queue.
postsuper -H ALL
- Re-queue messages, for example if postfix had a configuration error, after correcting it we can re-queue the messages so that any classification errors they may have suffered are corrected. For example, a change of 'delivery agent'.
postsuper -r ID_MSG
o
postsuper -r ALL
- See the content of a message that is in the queue:
postcat -q ID_MSG
- To force the re-sending of messages in the queue.
postqueue -s
o
postfix flush
- To force the sending of messages in the queue for a domain.
postqueue -s domini.com4 comments
Comments from the old blog, as they were written. Comments are closed.
Jorge Huerga
I després comentar que existeix el programa pfqueue que va de meravella per a gestionar les cues de correu! :)
Oriol Rius
mira els links q ja tens això a l'article
javivf
Sabia jo que em faria falta este post... gracies per compartir!
javivf
Sabia jo que em faria falta algun dia este post... gracies per compartir! :)