Perfect mail servers ensure lightening fast mail delivery. And, the mail reaches your friend in a split second.

Unfortunately, that’s not the case every time. Often, mails get stuck in the mail server queue resulting in delayed or failed emails. In mails servers like Postfix, this can happen due to spamming, bad mail server configuration, etc.

At Bobcares, we often address problems like Postfix mail stuck in queue as part of our Server Management Services.

Today, we’ll see how our Bobcares Engineers fix Postfix mail stuck in queue and make mail working.

Understanding Postfix mail queue

Before proceeding further, let’s have a quick look and understand Postfix mail queue.

By default, Postfix maintains 2 mail queues, pending and deferred. Pending queue contain mails that are not sent to remote server. Again, the Deferred queue hold the mails that has temporary failure. The Postfix mail server will retry sending the deferred queue mails on set intervals.

Therefore, at any point of time, the number of mails in the queue gives a quick status on the mail server. To view the number of emails in Postfix email queue, we can use the command:


For example, the output from a server having 4 mails in the queue with a total size of 19Kbytes will look as:

[root@pxxx ~]# mailq | tail -n 1
-- 19 Kbytes in 4 Requests.

Higher number of queued mails in the server indicate a problem on the Postfix server.

[Do you know that our server monitoring plan tracks number of mails in queue? We proactively fix mail queue before even the customer notices it.]


Reasons for Postfix mail stuck in queue

Now, that we have an idea on Postfix mail queue, let’s check on the reasons that would make mail stuck in queue.


1. Spamming

From our experience in server administration, our Support Engineers often see spamming as one of the major reasons for high mail queue.

When a spammer sends a large number of emails to non existing addresses, they fail and remain in the queue. Similarly, when the recipient server see too many mails from the same server, it will block all mails from it.

A sample entry in the server’s mail log at /var/log/mailog appears as:

May 10 03:36:13 pmxxx postfix/smtp[2446]: 48A6B1A7508: to=<>,[2xx.xx.17.8]:25, delay=189560, delays=189
557/0/2.8/1.1, dsn=4.0.0, status=deferred (host[2xx.xx.17.8] said: 450-Requested mail action not taken: mailbox unavailable 450 Reject due to policy violations. (in reply to RCPT TO command))

Again, certain servers send bounce messages back to the server. As a result, the mails get stuck in the server’s mail queue.


2. Scan program not running

Similarly, we often see mail to be stuck in Postfix queue when the antivirus program fails to work correctly. For example, in Postfix servers having MailScanner software scanning each email, problems appear when MailScanner stops. Likewise, other antivirus programs like Clamav, Amavis, etc. impact the Postfix mail delivery too.

For the proper working, these mail filtering services should be working on the server.


3. Incorrect Postfiix config

The wrong configuration in Postfix also causes mails to be stuck in the queue.

Recently, when one of our customers reported mails stuck in Postfix, the reason attributed to Postfix configuration. In the Postfix configuration file at /etc/postfix/, it was set to use all protocols. However, the server was blocking IPv6 protocols. This resulted in network error when sending mails to Gmail users.

Feb 16 19:13:25 ip-xx-xx-xx postfix/smtp[17128]: connect to[2607:f8b0:400e:c04::1a]:25: Network is unreachable
Feb 16 19:13:25 ip-xx-xx-xx postfix/smtp[17128]: A3AEE2026D: to=<>, relay=none, delay=361752, delays=361752/0.04/0.28/0, dsn=4.4.1, status=deferred (connect to[2607:f8b0:400e:c04::1a]:25: Network is unreachable)


How we correct Postfix mail queue

We already saw the possible errors. In many cases, simply forcing the email delivery will work. But, the problem will pop up again. Therefore, our Dedicated Engineers always fix the real root cause for the problem first.

Now, it’s time to see how we correct the Postfix mail queue and make mail working.


1. Fix Spamming

With a general analysis of the Postfix mail queue, our Server Administrators can quickly identify spamming on the server. In such cases, we additionally verify couple of emails in the queue using the command:

postcat -vq XXXXXXXXXX

Here, XXXXXXXXXX is the message id of mail stuck in queue. We check the headers of the email and understand the source of the email. Most probably, they will be sent from some php scripts that resides inside the website content. Or, it can be a compromised email account. In either cases, we disable the problem user and malicious spamming script.

Again, to avoid such spamming instances, we take adequate precautionary measures on the server. This include periodic scanning of website content, rate limiting emails on server, etc. For example, in servers with Plesk control panel, Outgoing mail rate limiting can be done based on domain, email addresses, etc. as below.


2. Restart Antivirus programs

In cases where antivirus become the problematic element, our Server Engineers first confirm whether it is running on the server. For instance, in case of MailScanner, we check the folder /var/run/MailScanner/ and look for the process id file. Missing id file means that the service is not running. Therefore, we do a restart using the command:

/etc/init.d/mailscanner restart

This would make MailScanner running again and Postfix start processing mails. We apply similar fix in case of other antivirus programs like Clamav too.


3. Correct Postfix configuration

Similarly, in certain cases, the fix may require edits in the Postfix configuration file too. For instance, when the customer had problems with IPv6 traffic on the server, we temporarily fixed it by making Postfix use only IPv4 protocol.

Here, we edited the file /etc/postfix/ and set the variable as below.

inet_protocols = ipv4

After restarting Postfix, mails started flowing from the server.


4. Force mails on Postfix

In all cases, after fixing the root cause, it will take too much time to process the mails stuck in Postfix queue. Therefore, our Support Engineers bring the mail count back to normal using the following steps.

Flush the mail queue that would immediately attempt to send all queued messages using

postqueue -f

Also, in some cases, we clear the deferred mails using:

postsuper -d ALL deferred

In case of spamming instances, we configure scripts to delete all queued emails that have a certain address in them.



Precisely, mails often get stuck in Postfix mail queue resulting in email delays. Today, we saw the various reasons for the error and how our Dedicated Engineers fix Postfix mail stuck in queue.

Source link


Write A Comment