Email & webmail

Manage the mail queue on Exim and Postfix from the command line

Command-line reference for viewing, inspecting, retrying and deleting queued messages on Exim and Postfix servers, finding the cause of deferrals and spotting spam floods.

AdvancedLinux mail servers3 min read

When email is delayed, the answer is usually in the mail queue: messages the server accepted but could not deliver yet. This guide is a practical reference for managing the mail queue on Exim (cPanel, DirectAdmin) and Postfix (Plesk, many self-built servers) from SSH.

Before you start

  • Root SSH access to the mail server.
  • On cPanel you can also use WHM → Email → Mail Queue Manager; the commands below are faster for large queues.

Warning: Deleting queued messages is permanent. Inspect before you delete, and never wipe the whole queue unless you are sure it contains only spam.

Exim queue commands

TaskCommand
Count messagesexim -bpc
List queueexim -bp
Summary by domainexim -bp | exiqsumm
Show headersexim -Mvh MESSAGE-ID
Show bodyexim -Mvb MESSAGE-ID
Show message logexim -Mvl MESSAGE-ID
Retry one messageexim -M MESSAGE-ID
Run the queueexim -qff
Remove one messageexim -Mrm MESSAGE-ID
Remove frozen messagesexiqgrep -z -i | xargs exim -Mrm
Messages from a senderexiqgrep -f sender@example.com -i
Messages to a domainexiqgrep -r example.net -i

Exim's main log is /var/log/exim_mainlog. Trace one message with exigrep MESSAGE-ID /var/log/exim_mainlog.

Postfix queue commands

TaskCommand
List queuepostqueue -p (or mailq)
Count messagespostqueue -j | wc -l (Postfix 3.1+)
Show a messagepostcat -vq QUEUE-ID
Retry all deferred mailpostqueue -f
Retry one messagepostqueue -i QUEUE-ID
Delete one messagepostsuper -d QUEUE-ID
Delete all deferred mailpostsuper -d ALL deferred
Hold / release a messagepostsuper -h QUEUE-ID / postsuper -H QUEUE-ID

Postfix logs to /var/log/mail.log, /var/log/maillog or the journal (journalctl -u postfix).

Find out why mail is deferred

  1. Read the reason in the queue listing or the message log.
  2. Common reasons:
    • Connection timed out – the remote server is down, or your outbound port 25 is blocked.
    • 4xx greylisting / try again later – normal; the server will retry.
    • 5xx rejected / blocked – your IP or domain is on a blocklist, or SPF/DKIM fails.
    • Mailbox full – the recipient's quota is exceeded.
  3. Fix the cause, then retry the queue.

Spotting a spam flood

A sudden queue of thousands usually means a hacked mailbox or script. Find the top senders:

exim -bp | awk '/^ *[0-9]+[mhd]/{print $4}' | sort | uniq -c | sort -rn | head

Then change the compromised password, disable the script, and remove that sender's messages with exiqgrep -f and exim -Mrm. On Postfix, check postqueue -p output and the logs for the authenticated user (sasl_username).

FAQ: mail queue

How long does a server keep retrying?

Typically several days (Exim's default retry rules and Postfix's maximal_queue_lifetime of 5 days) before bouncing the message.

What is a frozen message in Exim?

A message Exim stopped trying to deliver, often a bounce that could not be returned. Frozen bounces are usually safe to delete.

Should I flush the queue repeatedly?

No. Forcing retries does not fix the underlying cause and may hurt your reputation with remote servers.

Next steps

Was this guide helpful?

Still stuck?

Ask MdmHost AI for a quick answer, or open a ticket and our team will take a look. We are here 24/7.