Troubleshooting Delivery Issues

Managing Exim Mail Queue: Comprehensive Guide

By the Domain India teamPublished 8 min read
Knowledge base article
Contents (9 sections)

Exim is the mail server on most cPanel and DirectAdmin servers. When it can't deliver a message straight away, it keeps it in a queue and retries. This guide is for administrators of their own server or VPS: it covers the commands to inspect the queue, deliver or remove messages safely, and clean up after a spam run.

Key takeaways

exim -bpc counts queued messages, exim -bp lists them and exim -bp | exiqsumm summarises them by domain. exiqgrep selects messages by sender, recipient, age or frozen state, and -i prints just their IDs, which you pipe to xargs exim -Mrm to delete. exim -M MESSAGE-ID retries one message now and exim -q runs the whole queue. Never delete the whole queue as a reflex: it removes legitimate mail waiting for a retry.

Own-server guide

These commands need root access on a server you run. On shared hosting the provider manages the mail queue; on Domain India shared hosting, open a ticket if mail is stuck (section 8).

1. How the Exim queue works

When Exim accepts a message it tries to deliver it at once. If the receiving server is down, refuses with a temporary error such as a 421, or can't be reached, the message stays in the spool (/var/spool/exim/input) and Exim retries on a schedule. After its retry time runs out, the message bounces back to the sender.

A message that Exim can't deliver or bounce, such as a bounce whose own recipient is dead, becomes frozen. Frozen messages stay until an administrator thaws or removes them, or until the server's frozen-message timeout clears them.

A large or growing queue usually means one of three things: a remote provider is rate-limiting you, your server is sending spam, or a destination is down.

2. See what is in the queue

CommandWhat it shows
exim -bpcNumber of messages in the queue
exim -bpEach message: age, size, ID, sender and recipients
exim -bp, piped to exiqsummTotals per recipient domain, with oldest and newest
exiqgrep -c ...Count of messages matching a filter (see section 3)
exiwhatWhat each running Exim process is doing right now

For a quick view of where mail is going, sort the summary:

bash
exim -bp | exiqsumm | sort -rn | head -20

To look at one message:

bash
exim -Mvh 1uAbCd-0001Xy-2Z    # headers
exim -Mvb 1uAbCd-0001Xy-2Z    # body
exim -Mvl 1uAbCd-0001Xy-2Z    # this message's delivery log

The message log (-Mvl) is the fastest way to see why a message is stuck. The main log has the full history; it is /var/log/exim_mainlog on cPanel and /var/log/exim/mainlog on DirectAdmin, and exigrep MESSAGE-ID LOGFILE pulls out every line for one message.

3. Select messages with exiqgrep

exiqgrep reads the queue itself and filters it. Useful options:

OptionSelects
-f addressSender matches (a regular expression)
-r addressRecipient matches
-o secondsOlder than the given age
-y secondsYounger than the given age
-zFrozen messages only
-xMessages that are not frozen
-iPrint only the message IDs
-cPrint only the count

Examples:

bash
exiqgrep -c -f '[email protected]'   # how many from one sender
exiqgrep -r '@gmail\.com$'                 # everything to Gmail, with details
exiqgrep -z -i                             # IDs of frozen messages
exiqgrep -o 86400 -f '^<>$' -i             # bounces older than one day

Always run a filter with -c or without -i first, and read what it matches, before you pipe the IDs into a delete.

4. Deliver, freeze and thaw

CommandEffect
exim -M idTry to deliver this message now
exim -qRun the queue once, respecting retry times
exim -qfRun the queue and force a retry of every non-frozen message
exim -qffAs -qf, and also try frozen messages
exim -R domainRetry messages for one recipient domain
exim -Mf idFreeze a message so Exim stops trying it
exim -Mt idThaw a frozen message
exim -Mg idGive up: bounce the message back to the sender

Forcing a whole-queue run (-qf, -qff) against a provider that is rate-limiting you makes the problem worse. Fix the cause first, then let the normal retry schedule work.

5. Remove messages safely

exim -Mrm MESSAGE-ID deletes a message without delivering it or telling the sender. It accepts several IDs at once, so combine it with exiqgrep -i and xargs -r (which does nothing if no IDs match):

bash
# frozen messages
exiqgrep -z -i | xargs -r exim -Mrm

# everything from one compromised sender
exiqgrep -f '[email protected]' -i | xargs -r exim -Mrm

# bounces older than a day
exiqgrep -o 86400 -f '^<>$' -i | xargs -r exim -Mrm
Don't empty the whole queue without reading it

exiqgrep -i | xargs -r exim -Mrm deletes every queued message, including invoices, password resets and customer replies waiting for a retry. Their senders are never told. Use it only when you have confirmed the queue is entirely spam.

6. Clean up after a spam run

A queue of thousands of messages to random addresses usually means a hacked mailbox or a PHP script sending spam. Stop the source before you delete anything, or the queue refills.

  1. Find the sender. Use `exim -bp
    exiqsumm and exiqgrep to find the sender address or domain. On cPanel, the cwd=` field in the main log shows which folder a PHP script sent from.
  2. Stop it.
    Change the password of a compromised mailbox, or disable or fix the abused script or contact form.
  3. Remove the spam. Delete that sender's messages with `exiqgrep -f ... -i
    xargs -r exim -Mrm, then the frozen bounces with exiqgrep -z -i`.
  4. Check your reputation.
    Look up your server IP on blocklists and check SPF, DKIM and DMARC, as described in the Exim 421 guide.
  5. Watch the queue.
    Run exim -bpc again over the next hour to confirm it stays small.

7. Panel tools

Both panels have a graphical view of the same queue. On cPanel, WHM has a Mail Queue Manager for searching, delivering and deleting queued messages. DirectAdmin has a mail queue page at admin level. Menu names change between versions; the command line always works.

8. On Domain India hosting

Shared hosting: the mail queue belongs to the server, so customers can't view or change it. If your mail is stuck or bouncing, check the sending limit (200 messages per hour per account on cPanel, 1,000 per day on DirectAdmin), read I can receive mail but I cannot send it, and open a ticket with the recipient address and the time you sent it.

Your own server: a Domain India VPS is self-managed with full root access. With the DirectAdmin panel option it runs Exim, so every command here works on it.

Frequently asked questions

How do I check the Exim mail queue?

Run exim -bpc for the number of queued messages and exim -bp for the full list. Pipe exim -bp into exiqsumm to see totals per recipient domain.

How do I delete frozen messages in Exim?

Run exiqgrep -z -i to list the IDs of frozen messages, check them, then pipe them to exim -Mrm with: exiqgrep -z -i | xargs -r exim -Mrm.

How do I delete all mail from one sender in the Exim queue?

First count the matches with exiqgrep -c -f followed by the sender address. If the list is right, delete them with exiqgrep -f followed by the address and -i, piped to xargs -r exim -Mrm.

Does exim -Mrm deliver the message before removing it?

No. exim -Mrm deletes the message without delivering it and without telling the sender. To deliver a message now, use exim -M with the message ID.

How do I force Exim to retry the whole queue?

exim -qf retries every message that is not frozen, and exim -qff includes frozen ones. Don't force a queue run while a remote provider is rate-limiting you; fix the cause first.

Can I manage the mail queue on shared hosting?

No. On shared hosting the provider manages the mail server and its queue. On Domain India shared hosting, open a support ticket with the recipient and the time you sent the message.

Ready to go further? Read Fixing the Exim 421 error for deliverability problems, or see VPS plans if you want your own mail server.

Mail stuck on your hosting?

Send us the sender, the recipient and the time the message was sent, and we will check the mail queue and logs for you.

Open a support ticket

Ready when you are

Get Business Email from ₹60/mo + GST

See plans

Was this article helpful?

Your answer helps us decide what to improve next.

Still need help? Open a support ticket and our team will reply.

Prefer an app? Add this site to your home screen.Get the app