przyrostek

Postfix Mail Queue Management

Postfix Mail Queue Management
Postfix Mail System is the one of the most widely used mail systems along with Exim. In the initial days postfix was widely used for custom setup and custom Mail server setups. But nowadays Plesk servers also has Postfix as the default mail server and not Qmail. In this blog, we mainly concentrate on Mail Queue Management commands which almost all server owners and server administrator may need at some point of time.

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.

  1. maildrop
  2. hold
  3. incoming
  4. active
  5. deferred
  6. Corrupt

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:

/var/spool/postfix/maildrop
/var/spool/postfix/hold
/var/spool/postfix/incoming
/var/spool/postfix/active
/var/spool/postfix/deferred
/var/spool/postfix/corrupt

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

# postqueue -p
Sample Output
[root@host1 ~]# postqueue  -p
-Queue ID- --Size-- ----Arrival Time---- -Sender/Recipient-------
C79CEC3F6BC*     526 Wed Dec  5 15:05:18  [email protected]
[email protected]

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 “Queue ID”
# postcat -q C79CEC3F6BC

To check the total number of mails in the queue

# postqueue -p | grep -c "^[A-Z0-9]"

To reattempt delivery of all mails in the queue

# postqueue -f

To remove all Mails in the Queue

# postsuper -d ALL

To remove all mails in the deferred Queue

# postsuper -d ALL deferred

To remove particular mail in the queue.

# postsuper -d “Queue ID”
# postsuper -d C79CEC3F6BC

To remove all mails from a particular mail id

[email protected]

# mailq | tail +2 | awk 'BEGIN RS = "" / [email protected]\.com$/ print $1 ' |
tr -d '*!' | postsuper -d -

To attempt to send one particular mail

# postqueue -i “Queue ID”
# 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.

# for id in 'postqueue -p|grep '^[A-Z0-9]'|cut -f1 -d"|sed 's/*//g"; do postcat -q $id
| 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.

# for id in 'postqueue -p|grep '^[A-Z0-9]'|cut -f1 -d"|sed 's/*//g";
do postcat -q $id | grep “X-PHP-Originating-Script: 48:badmailing.php”
&& postsuper -d $id; done

Conclusion

I hope this article helps you get more comfortable with Postfix Mail Queue Management.

Gry Najlepsze dystrybucje Linuksa do gier w 2021 r
Najlepsze dystrybucje Linuksa do gier w 2021 r
System operacyjny Linux przeszedł długą drogę od pierwotnego, prostego, serwerowego wyglądu. Ten system operacyjny znacznie się poprawił w ostatnich l...
Gry Jak przechwytywać i przesyłać strumieniowo sesję gry w systemie Linux
Jak przechwytywać i przesyłać strumieniowo sesję gry w systemie Linux
W przeszłości granie w gry było uważane tylko za hobby, ale z czasem branża gier odnotowała ogromny wzrost pod względem technologii i liczby graczy. P...
Gry Najlepsze gry do grania ze śledzeniem rąk
Najlepsze gry do grania ze śledzeniem rąk
Oculus Quest niedawno wprowadził świetny pomysł śledzenia rąk bez kontrolerów. Przy stale rosnącej liczbie gier i działań, które wspierają zarówno for...