Postfix has five different queues and they are listed below. All mails which postfix handles will stay in the server in one of these queues until the message leaves from the server.
You can get a detailed reference of all the above queues from this link. Postfix uses a separate directory for each of the above queues and the default directory for those are:
The above is just a reference for the queue structure and below is the actual set of commands which a server owner or a server administrator needs to handle a Postfix Mail queue and I will also mention how to find out a spamming instance as well so that you can get a more detailed idea on postfix queue management.
Display the list of Queued mails , deferred mails, and Pending mails
[root@host1 ~]# postqueue -p
-Queue ID- --Size-- ----Arrival Time---- -Sender/Recipient-------
C79CEC3F6BC* 526 Wed Dec 5 15:05:18 email@example.com
In the above result, Queue ID is C79CEC3F6BC and we need this for all future checks
To Display the mail header and contents
# postcat -q C79CEC3F6BC
To check the total number of mails in the queue
To reattempt delivery of all mails in the queue
To remove all Mails in the Queue
To remove all mails in the deferred Queue
To remove particular mail in the queue.
# postsuper -d C79CEC3F6BC
tr -d '*!' | postsuper -d -
To attempt to send one particular mail
# postqueue -I C79CEC3F6BC
To clear the infected mails by user or pattern
To clear the infected mails sent by a specific user or any specific pattern, you can use the below one. This will simply check that content which is searching and will remove all those emails which contains that pattern.
To remove all mails which have [email protected] in the entire mail.
| grep [email protected] && postsuper -d $id; done
To remove all mails which have a particular pattern like “X-PHP-Originating-Script: 48:badmailing.php” we can use the above script as below. When you are giving a longer pattern, make sure you copy paste all space and give all those exactly in the double quotes.
do postcat -q $id | grep “X-PHP-Originating-Script: 48:badmailing.php”
&& postsuper -d $id; done
I hope this article helps you get more comfortable with Postfix Mail Queue Management.