Postfix Mail Queue Management

29/12/2020
Chưa phân loại
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  root@host1.server.com
test.test@gmail.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 “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]$/ { 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 “XPHPOriginatingScript: 48:badmailing.php”
&& postsuper d $id; done

Conclusion

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

ONET IDC thành lập vào năm 2012, là công ty chuyên nghiệp tại Việt Nam trong lĩnh vực cung cấp dịch vụ Hosting, VPS, máy chủ vật lý, dịch vụ Firewall Anti DDoS, SSL… Với 10 năm xây dựng và phát triển, ứng dụng nhiều công nghệ hiện đại, ONET IDC đã giúp hàng ngàn khách hàng tin tưởng lựa chọn, mang lại sự ổn định tuyệt đối cho website của khách hàng để thúc đẩy việc kinh doanh đạt được hiệu quả và thành công.
Bài viết liên quan

How to Manually Install Fonts in Ubuntu 20

Texts are an important source of communication and very important, as a lot of the information that people get comes from...
28/12/2020

How to Use rsync Command to Copy Files on Ubuntu

rsync is a tool for copying files. rsync is used to copy files from your computer to a remote machine, from a remote machine...
29/12/2020

Git – Push Changes to Remote Git Branch

In this article, I am going to show you how to push (upload) your local Git repository to a remote Git repository hosted...
29/12/2020
Bài Viết

Bài Viết Mới Cập Nhật

Reliable IPv4 and IPv6 Subnet Rental Services: The Perfect Solution for Global Businesses
23/12/2024

Tìm Hiểu Về Thuê Proxy US – Lợi Ích và Cách Sử Dụng Hiệu Quả
11/12/2024

Mua Proxy V6 Nuôi Facebook Spam Hiệu Quả Tại Onetcomvn
03/06/2024

Hướng dẫn cách sử dụng ProxyDroid để duyệt web ẩn danh
03/06/2024

Mua proxy Onet uy tín tại Onet.com.vn
03/06/2024