Queue Inspection

These commands let you see what's sitting in the Exim mail queue — waiting to be delivered, frozen, or deferred.

Show all messages in the queue with details:

exim -bp

Output includes message ID, age, size, sender, and recipient for each queued message. Frozen messages are marked with *** or flagged as frozen.

Count messages in the queue:

exim -bpc

Returns a single integer — the total number of messages currently in the queue. Useful for monitoring scripts and alerts.

Show queue summary grouped by domain:

exim -bp | exiqsumm

exiqsumm is a Perl script included with Exim that summarises queue contents by recipient domain — useful when diagnosing a delivery problem to a specific destination.

List message IDs only (pipe-friendly):

exim -bp | grep '^ *[0-9]' | awk '{print $3}'

Extracts just the message IDs for use in loops and bulk operations.

Show details for a specific message:

exim -Mvh <message-id>

Displays the message headers. Replace -Mvh with -Mvb to see the message body, or -Mvi for the message's internal Exim metadata file.

Flushing and Retrying the Queue

When you've fixed a delivery problem (DNS issue, greylisting, remote server was down), you'll want to retry queued messages immediately rather than waiting for the next scheduled queue run.

Flush the queue — attempt delivery of all queued messages now:

exim -qff

The -qff flag means "queue run, force frozen". It retries all messages including frozen ones. Use -q alone to retry non-frozen messages only, or -qf to force a queue run without delivering frozen messages.

Queue run flags explained:

FlagBehaviour
exim -qStandard queue run — retries deferred messages, skips frozen
exim -qfForce queue run — delivers even if retry timer hasn't expired
exim -qffForce queue run including frozen messages
exim -qqffTwo-pass queue run forcing frozen — more thorough on large queues

Retry a single specific message:

exim -M <message-id>

Removing Messages from the Queue

Sometimes you need to remove messages from the queue — spam that got queued before filtering was applied, messages to a dead domain, or test messages you don't want delivered.

Remove a single message by ID:

exim -Mrm <message-id>

Remove all frozen messages (bulk):

exiqgrep -z -i | xargs exim -Mrm

exiqgrep -z lists frozen message IDs. -i outputs IDs only. The result is piped to exim -Mrm for bulk removal.

Remove all messages from a specific sender:

exiqgrep -i -f 'sender@example.com' | xargs exim -Mrm

Remove all messages to a specific recipient domain:

exiqgrep -i -r '@baddomain.com' | xargs exim -Mrm

Remove all messages in the queue (nuclear option — use with caution):

exim -bp | awk '/^ *[0-9]/ {print $3}' | xargs exim -Mrm
⚠️
Removing all messages from the queue is irreversible. There is no undo. Only use the bulk remove command if you are certain the queue contains only unwanted messages — for example, after a spam relay incident or during queue cleanup.

Checking Routing and Address Testing

Before sending mail to an address, or when debugging delivery failures, you can ask Exim how it would route a message without actually sending it.

Test how Exim would route an email address:

exim -bt user@example.com

Shows the router and transport that would handle delivery, the next-hop MX, and any rewriting rules that apply. Invaluable for debugging misrouted mail.

Test address with debug output:

exim -d -bt user@example.com 2>&1 | less

The -d flag enables full debug output — shows every decision Exim makes while routing, including ACL checks, router matching, and transport selection.

Verify an address is syntactically valid:

exim -bv user@example.com

Check what MX records Exim would use:

exim -bt -v user@example.com

Testing SMTP Delivery

You can feed raw SMTP commands to Exim for testing without needing to open a real SMTP connection. This is useful for testing ACLs, spam filters, and local delivery.

Send a test email from the command line:

echo "Test message body" | exim -v -f sender@example.com recipient@example.com

The -v flag shows verbose delivery output. Exim will attempt delivery immediately and show you the result.

Feed a full RFC 2822 message to Exim (SMTP batch mode):

exim -bS << EOF
EHLO testhost
MAIL FROM:<sender@example.com>
RCPT TO:<recipient@example.com>
DATA
From: sender@example.com
To: recipient@example.com
Subject: Test

This is a test message.
.
QUIT
EOF

Test Exim's SMTP server directly with telnet or netcat:

telnet localhost 25

Then type SMTP commands manually. Press Ctrl+] then type quit to exit telnet.

Viewing and Analysing Mail Logs

Exim logs are typically at /var/log/exim4/mainlog (Debian/Ubuntu) or /var/log/exim/mainlog (RHEL/CentOS). The log format is line-based with a timestamp and message ID on each line.

Follow the Exim main log in real time:

tail -f /var/log/exim4/mainlog

Show all log entries for a specific message ID:

grep '1abc12-000001-AB' /var/log/exim4/mainlog

Find all delivery failures (bounces) in the log:

grep 'rejected\|bounce\|failed\|SMTP error' /var/log/exim4/mainlog | tail -100

Find all messages rejected by ACL (spam/policy rejections):

grep 'rejected after DATA\|rejected RCPT' /var/log/exim4/mainlog | tail -50

Count deliveries per hour (quick volume check):

grep 'Completed' /var/log/exim4/mainlog | awk '{print $1, $2}' | cut -c1-13 | sort | uniq -c

Find top sending IPs (useful after spam incident):

grep 'SMTP connection from' /var/log/exim4/mainlog | grep -oP '\[[\d.]+\]' | sort | uniq -c | sort -rn | head -20

Search across gzipped rotated logs:

zgrep 'user@example.com' /var/log/exim4/mainlog.*.gz

Handling Frozen Messages in Bulk

Frozen messages are ones Exim has given up retrying temporarily. They accumulate when a remote server is persistently down, or when messages are undeliverable. You need to either thaw (retry) or remove them.

Count frozen messages:

exiqgrep -z -c

List frozen message IDs:

exiqgrep -z -i

Thaw (unfreeze) all frozen messages so Exim will retry them:

exiqgrep -z -i | xargs exim -Mt

Remove all frozen messages:

exiqgrep -z -i | xargs exim -Mrm

Freeze a specific message manually (stop delivery attempts):

exim -Mf <message-id>

Thaw a specific frozen message:

exim -Mt <message-id>
ℹ️
If frozen messages keep accumulating, check the Exim mainlog for the specific error causing them to freeze. Common causes: remote MX not accepting connections, DNS resolution failures, local delivery quota exceeded, or misconfigured transports.

Checking Exim Version and Configuration

Check Exim version:

exim --version

Or:

exim -bV

This also shows compile-time options, which tells you what features are compiled in (TLS, DKIM, SPF support, etc.).

Show Exim configuration file location:

exim -bP config_file

Verify Exim configuration syntax (dry-run config check):

exim -C /etc/exim4/exim4.conf -bV

If the configuration has syntax errors, Exim will report them here without affecting the running daemon.

Show all Exim configuration options currently in use:

exim -bP

Check Exim's process status:

systemctl status exim4

Or on older init systems:

service exim4 status

Restart Exim (Debian/Ubuntu):

systemctl restart exim4

Reload Exim configuration without restart:

systemctl reload exim4

Or send SIGHUP to the Exim daemon PID:

kill -HUP $(cat /var/run/exim4/exim.pid)

Quick Reference Table

TaskCommand
Show queueexim -bp
Count queueexim -bpc
Flush queue (incl. frozen)exim -qff
Remove single messageexim -Mrm <id>
Remove all frozenexiqgrep -z -i | xargs exim -Mrm
Thaw all frozenexiqgrep -z -i | xargs exim -Mt
Test routing for addressexim -bt user@domain.com
View message headersexim -Mvh <id>
View message bodyexim -Mvb <id>
Retry single messageexim -M <id>
Freeze single messageexim -Mf <id>
Check versionexim -bV
Check config syntaxexim -bV -C /path/to/exim.conf
Watch mail logtail -f /var/log/exim4/mainlog
Count frozen messagesexiqgrep -z -c

Need Help?

Melbits provides managed IT support for Melbourne businesses, including Linux server administration and email server management. If your Exim server is having delivery issues, accumulating frozen messages, or you suspect it's been used for spam relay, contact us for assistance. Call 1800 635 248 or get in touch online.