Exim Queue Management Tutorial

Print Friendly, PDF & Email

So, you have got yourself a shiney new dedicated or VPS server with cPanel or DirectAdmin or some such installed. It probably won’t be long before you have to start checking the exim mail logs and the exim mail queue to trace problems being encountered by customers.

I have put this article here more as an aide-memoir than anything. If anyone finds it useful, I’d love to hear from you!

Respect the exim queue

One of worst things you could ever do as an admin, when finding a mail queue with hundreds or thousands of frozen or delayed messages in it, is to simply clear the queue. DONT DO THIS! You might just as well not run a mail server at all. The messages you remove in this way will just vanish without a trace – your customers and the people they communicate with won’t have a clue what happened, and your service will soon be viewed as unreliable.

Sadly, many inexperienced admins use the graphical UI to do just that – because it’s easy. However, with just a few simple commands, it can become possible to inspect and manage the queue with much greater elegance.

So, read on to find out how Exim queue management can be done from the command line.

Basic exim queue management

# a count of all messages in queue
exim -bpc
 
# a list of message in the queue (time queued, message size, message id, sender, recipient)
exim -bp
 
# a summary of all messages in queue (count, volume, oldest, newest, destination domain)
exim -bp | exiqsumm
 
# determine how exim would route a message
exim -bt user@domain.com
 
# test how exim would deal with a connection from a specific IP address.
# this will display Exim's filters and ACLs
exim -bh 192.168.1.1

How to search the exim queue with exiqgrep

exiqgrep is commonly used with the following switches:

# lists messages from a specified sender
exiqgrep -f [user]@domain
 
# lists messages to a specified recipient
exiqgrep -r [user]@domain
 
# lists messages older than a number of seconds
exiqgrep -o [seconds]
 
# lists messages younger than a number of seconds
exiqgrep -y [seconds]
 
# lists messages that match the specified size (can be a regex)
exiqgrep -s '^2...$'

You can combine the following switches to further restrict the output of the above

-i to just list the message IDs

-z to just show frozen messages

-x to just show unfrozen messages

Exim queue management

Queue management is performed with the exim command. However, we often use exiqgrep to filter data before feeding it to exim via the command line. Here are the basic and most popular queue operations:

# Start a queue run (won't run if over load threshold)
exim -q -v
 
# Force a queue run (will run regardless of load)
exim -qf -v
 
# Start queue run for local deliveries only
exim -ql -v
 
# Remove a message from queue by ID
exim -Mrm <message-id> ...
 
# Freeze a message
exim -Mf <message-id> ...
 
# Thaw a message
exim -Mt <message-d> ...
 
# Force delivery of a message regardless of Frozen status
exim -M <message-id> ...
 
# View a message's logs
exim Mvl
 
# View a message's headers
exim Mvh
 
# View a message's body
exim Mvb

Now for some advanced exim queue management

OK, so that’s the basics out of the way, here’s a few combined commands that I use from time to time. I should make it clear at this point that I am no Exim guru, and would welcome any input to these command that ight improve them – I’ve put these together over countless hours of digging through exim’s queues trying to trace problems with message delivery.

# List all queued messages, grouped by sender address
exim -bpr | grep -Eo "<[^ ]*@[^ ]*>" | sort | uniq -c
 
# List all queued messages, grouped by recipient address
exim -bpr | grep -Eo "^\s*[^ ]*@[^ ]*$" | sort | uniq -c
 
# Remove all messages older than 12hrs (43000 seconds)
exiqgrep -o 43000 -i | xargs exim -Mrm
 
# Remove all frozen messages from the queue
exiqgrep -z -i | xargs exim -Mrm
 
# Remove all messages from a particular sender
exiqgrep -i -f [user]@domain.com | xargs exim -Mrm
 
# Remove all messages from a sender that are older than 12hrs
exiqgrep -o 43000 -i -f [user]@domain.com | xargs exim -Mrm

Tags: , , , , ,

2 Responses to “Exim Queue Management Tutorial”