A mail server does not always deliver a message on the first attempt. When the destination is busy, unreachable or unwilling, the server keeps the message in a queue and tries again later. A small, short-lived queue is normal and healthy. A queue that grows without draining is a symptom of a problem: a network fault, a blocked destination, a broken DNS resolver, a misconfigured relay or, in the worst case, a compromised account sending spam. Knowing how to read the queue, interpret the reasons given for deferral and respond without losing legitimate mail is a core operational skill. This guide uses Postfix commands in examples because it is widely deployed, and mentions equivalents for Exim. The concepts apply to any MTA, including managed platforms where you see the same states through a dashboard. See also what a queued email means and 421 deferrals.
How a queue works
In Postfix, messages move between queues: incoming and active for mail being processed, deferred for mail that could not be delivered yet, hold for mail an administrator has paused and corrupt for damaged files. Deferred messages are retried with increasing delay, between a minimum and maximum retry time, until the maximum queue lifetime (by default several days) is reached, after which the server returns a bounce to the sender. Other MTAs use similar ideas with different names. See retries and backoff.
Looking at the queue
postqueue -p # list the queue (also: mailq)
postqueue -p | tail -1 # summary line: -- 1234 Kbytes in 87 Requests.
postcat -q 4F2A81C3D9 # show one queued message with headers
qshape deferred # age distribution of deferred mail by recipient domain
postconf mail_version # confirm the version you are working withThe listing shows the queue ID, size, arrival time, sender and recipients, with the reason a message is deferred in parentheses. For example: (connect to mx.example.net[203.0.113.5]:25: Connection timed out). The command qshape deferred groups messages by domain and age, which quickly reveals whether one destination is responsible for most of the backlog. For Exim the equivalents are exim -bp, exim -bpc for a count and exiqsumm for a summary.
Reading the deferral reason
| Reason in the queue | Likely cause | What to do |
|---|---|---|
| Connection timed out / refused | Remote server unreachable, firewall or port 25 blocked | Test connectivity from the server. See connection timeouts |
| Host or domain name not found | DNS failure or typo in the domain | Check the resolver and the domain. See MX records |
| Temporary lookup failure | Local resolver problem | Fix DNS on the server; restart the resolver |
| 421, 450, 451, 452 with a rate or policy message | Remote throttling or greylisting | Slow down; check reputation. See 451 errors and 452 limits |
| TLS handshake errors | Certificate or protocol mismatch | Review TLS settings. See SMTP certificates |
| Mailbox full (452 4.2.2) | Recipient over quota | Wait or contact the sender. See mailbox full |
| Relay access denied / authentication required | Relay host rejects your server | Fix credentials or IP allowlisting. See Postfix relay setup |
| Blocked using a blocklist or reputation | Your IP is listed | Check with the blocklist check. See delisting |
| Lost connection after DATA | Remote closed the session, content or size issue | Review message size and content. See 421 timeouts |
Dealing with a growing queue
- Measure. Count messages (
postqueue -p | grep -c "^[A-F0-9]") and view the age distribution. Compare with the normal baseline. - Find the dominant reason and destination, using qshape and the reasons in the listing.
- Check the basics: DNS resolution, outbound port 25, disk space, load, time synchronisation and the mail log.
- Decide whether the mail is legitimate. Look at senders, subjects and volumes. Many messages from one sender to random recipients, or from an unfamiliar local user, indicate a compromised account or script.
- Stop the source first if mail is bad: disable the account, change credentials, block the script, then deal with the queue. See account compromise response.
- Fix the cause of deferral for legitimate mail, then let normal retries run or flush.
- Watch it drain. A healthy queue shrinks steadily; sudden re-growth means the cause remains.
Flush, hold, requeue and purge
| Command | Effect | Use with care |
|---|---|---|
| postqueue -f | Attempt immediate delivery of all deferred mail | Can hammer destinations that are throttling you; flush only after fixing the cause |
| postqueue -s example.net | Flush mail for one domain | Safer, targeted |
| postsuper -h ID | Hold a message so it is not delivered | Good for suspicious mail pending review |
| postsuper -H ID | Release a held message | Review first |
| postsuper -r ALL deferred | Requeue deferred messages, re-evaluating routing | Useful after changing transport maps or DNS |
| postsuper -d ID | Delete one message | Irreversible |
| postsuper -d ALL deferred | Delete all deferred mail | Almost never correct; deletes customer mail without bounce notices |
To delete only the spam, filter by sender or recipient rather than wiping the queue, and keep a copy of what you remove if you may need to investigate. Remember that deleting a message gives the original sender no notice. If legitimate mail must be abandoned, it is kinder to let it expire naturally with a bounce, or to notify the sender. For a hold-and-review workflow, move suspect messages to hold, inspect samples with postcat, then delete the confirmed spam by ID.
Worked example
Suppose the queue jumps from about 200 messages to 12,000 within an hour. The age listing shows most of the mail is under sixty minutes old and addressed to hundreds of different domains, and the senders are all one local user, which points to a compromised account or script. You disable the account, hold the messages from that sender, inspect a few with the queue content command, confirm they are spam and delete them by ID. The remaining legitimate mail is flushed. Afterwards you add a per-user rate limit and check the outbound IP against blocklists, since the burst may already have caused listings. Had the age listing instead shown old mail for a single domain, the cause would be that destination, and the response a connectivity test, not a purge.
Prevent backlogs
- Rate-limit by sender. Limit messages per user per hour so that a compromised account cannot flood the queue.
- Authenticate submissions and never run an open relay. See IP allowlists.
- Use sensible concurrency per destination so that you do not trigger remote throttling.
- Separate queues or transports for transactional and bulk mail, so a bulk backlog does not delay password resets. See separate streams.
- Set a reasonable maximum queue lifetime for your business; a short lifetime for time-sensitive mail avoids delivering stale messages days later.
- Keep disk space and inodes available. A full disk stops the queue.
- Monitor DNS and outbound connectivity as part of mail health.
Monitoring
Alert on queue size, oldest message age, the number of deferred messages per destination and the delivery rate. A simple check on the queue count with warning and critical thresholds catches most incidents, and an age-based alert catches slow leaks that a count would miss. Graph the values so you can see patterns, such as a nightly batch that raises the count briefly. Log deferral reasons in a structured way so that dashboards show which reasons dominate. See delivery monitoring and the incident runbook.
A queue is a buffer that tells you about the health of everything around it. Read it before you touch it, find the reason that dominates, fix that cause and let the retries do the work.
Skip the queue management Use a managed relay with built-in retries and delivery logs.
References and further reading
Frequently asked questions
Why are my emails stuck in the queue?
They are deferred after a temporary failure such as a timeout, DNS problem, throttling or a blocklist. Read the reason in the queue listing.
Is it safe to flush the queue?
Only after fixing the cause. Flushing during throttling or a block can make things worse; target specific domains where possible.
How do I delete only spam from the queue?
Filter by sender, recipient or content and delete by queue ID, rather than purging the whole queue.
How long do queued messages stay?
Until delivered or until the maximum queue lifetime is reached, after which a bounce is returned. Postfix defaults to several days.
What is the first sign of a compromised account?
A sudden queue of messages from one local user to many unrelated recipients.