postqueue guide

Posted on Tuesday June 6th, 2017

This is a quick and dirty guide to the postfix queue - which handles mail which is queued for delivery but not sent (as yet).

To see what's in the queue, issue this command:

postqueue -p

which produces output similar to this:

5642B4D8647* 1683500 Tue Jun  3 08:37:27  xxxxxx@xxxxxxx.com
                                         rrrrrrrrr@example.com

9359B4D82B1* 1635730 Tue Jun  3 08:36:53  xxxxxx@xxxxxxx.com
                                         yyyyyyyy@example.com

To force a flush of the queue (basically, try to send eveything in the queue) issue the command:

postqueue -f

You can also use the message ID (the first number in the queue list entries) to specify that mail to be deleted with the postsuper command. For example:

postsuper -d 5642B4D8647

If you have a list of message ids in a file (one per line) to delete, then a simple script can be written:

#!/bin/bash
input="/path/to/file"
while IFS= read -r var
do
  postsuper -d $var
done < "$input"

Finally to delete all deferred messages:

postsuper -d deferred

Credit where credit is due:
https://www.cyberciti.biz/faq/unix-howto-read-line-by-line-from-file/
https://www.garron.me/en/linux/delete-purge-flush-mail-queue-postfix.html