Exim Cheatsheet

I’m gathering a list of useful commands to use on an Exim 4.x server(with cPanel). Exim is the default Mail Transfer Agent on cPanel servers and you should have at least a small idea on how it works before using them.

File locations and Message-IDs

Exim uses Message-IDs to refer to messages in the queue. These IDsare are mixed-case alpha-numeric, and take the form of: XXXXXX-YYYYYY-ZZ(e.g. 1YDDgQ-000Cjf-CS). Most commands interact with the queue based on these IDs if you chose to use exim or exim’s tools to manage them. These messages are stored in files which are located under the following default paths in your system and there are three files for each message. If your queue has 10.000 emails you’re looking at 30.000 used Innodes on your system.

/var/spool/exim/msglog
Contains logging information for each message, files have the same name as the message-ID
/var/spool/exim/input
Contains header and data files the same name the message-ID along with a suffix to determine if this is a header file (-H) or a data one (-D)

The msglog and input folders contain multiple subfolders that help dealing with large mail queues and avoid causing problems due to high number of files in a single folder.

Basic Queue information

Print the amount of messages in the queue:
root@mail [~]# exim -bpc

Print more details from the queue like time in the queue, size of the message, message-ID, sender, recipient along with status:
root@mail [~]# exim -bp

Print stats based on the latest mail log:
root@mail [~]# eximstats /var/log/exim_mainlog

Print exim’s configuration:
root@mail [~]# exim -bP

Print what exim’s doing:
root@mail [~]# exiwhat

View headers for one message:
root@mail [~]# exim -Mvh [message ID]

View body for one message:
root@mail [~]# exim -Mvb [message ID]

Using exiqgrep to search the queue

Search for messages sent from sender at domain.com:
root@mail [~]# exiqgrep -f [sender]@domain.com

Search for messages sent TO recipient at domain.com:
root@mail [~]# exiqgrep -r [recipient]@domain.com

Print all message IDs from the queue:
root@mail [~]# exiqgrep -i

Search for messages older than 12 hours:
root@mail [~]# exiqgrep -o 43200

Search for messages newer than 12 hours:
root@mail [~]# exiqgrep -y 43200

Manage the queue

Start a queue run:
root@mail [~]# exim -q -v

Force a queue run:
root@mail [~]# exim -qff

Force a queue run for local email delivery:
root@mail [~]# exim -q1 -v

Remove a(multiple) message(s) from the queue:
root@mail [~]# exim -Mrm [message ID1] [message ID2] [message ID3]

Remove messages sent by jonathan@domain.com:
root@mail [~]# exiqgrep -i -f 'jonathan@domain.com' | xargs exim -Mrm

Remove all frozen messages from the queue:
root@mail [~]# exiqgrep -z -i | xargs exim -Mrm

Remove all messages from the queue:
root@mail [~]# exiqgrep -i | xargs exim -Mrm

If you have 999999999 emails in the queue due to an account compromise or a problem with your mailing system the above method might be slow. You can remove the queue content manually, including folders and files and re-create new ones, with minimal downtime to the mail service:
root@mail [~]# mv /var/spool/exim /var/spool/exim.OLD
root@mail [~]# mkdir -p /var/spool/exim/input
root@mail [~]# mkdir -p /var/spool/exim/msglog
root@mail [~]# mkdir -p /var/spool/exim/db
root@mail [~]# chown -R exim:exim /var/spool/exim/
root@mail [~]# /etc/init.d/exim restart
root@mail [~]# rm -rf /var/spool/exim.OLD

Documentation:

Exim Internet Mailer – Exim Homepage
Exim Utilities
Exim Command Line