Exim - General Information

Some useful(perhaps) information about exim.

Message-IDs and spool files

The message-IDs that Exim uses to refer to messages in its queue are mixed-case alpha-numeric, and take the form of: XXXXXX-YYYYYY-ZZ. Most commands related to managing the queue and logging use these message-ids.

There are three -- count 'em, THREE -- files for each message in the spool directory. If you're dealing with these files by hand, instead of using the appropriate exim commands as detailed below, make sure you get them all, and don't leave Exim with remnants of messages in the queue.

Files in /var/spool/exim/msglog contain logging information for each message and are named the same as the message-id.

Files in /var/spool/exim/input are named after the message-id, plus a suffix denoting whether it is the envelope header (-H) or message data (-D).

These directories may contain further hashed subdirectories to deal with larger mail queues, so don't expect everything to always appear directly in the top /var/spool/exim/input or /var/spool/exim/msglog directories; any searches or greps will need to be recursive. See if there is a proper way to do what you're doing before working directly on the spool files.

Queue information

Print a count of the messages in the queue:

Code: root@localhost# exim -bpc

Print a listing of the messages in the queue (time queued, size, message-id, sender, recipient):

Code: root@localhost# exim -bp

Print a summary of messages in the queue (count, volume, oldest, newest, domain, and totals):

Code: root@localhost# exim -bp | exiqsumm

Generate and display Exim stats from a logfile:

Code: root@localhost# eximstats /path/to/exim_mainlog

Same as above, with less verbose output:

Code: root@localhost# eximstats -ne -nr -nt /path/to/exim_mainlog

Same as above, for one particular day:

Code: root@localhost# fgrep YYYY-MM-DD /path/to/exim_mainlog | eximstats

Print what Exim is doing right now:

Code: root@localhost# exiwhat

Searching the queue

Exim includes a utility that is quite nice for grepping through the queue, called exiqgrep. Learn it. Know it. Live it. If you're not using this, and if you're not familiar with the various flags it uses, you're probably doing things the hard way, like piping `exim -bp` into awk, grep, cut, or `wc -l`. Don't make life harder than it already is.

Search the queue for messages from a specific sender:

Code: root@localhost# exiqgrep -f [luser]@domain

Search the queue for messages for a specific recipient/domain:

Code: root@localhost# exiqgrep -r [luser]@domain

Print just the message-id as a result of one of the above two searches:

Code: root@localhost# exiqgrep -i [ -r | -f ] ...

Print a count of messages matching one of the above searches:

Code: root@localhost# exiqgrep -c [ -r | -f ] ...

Print just the message-id of the entire queue:

Code: root@localhost# exiqgrep -i

Managing the queue

Start a queue run:

Code: root@localhost# exim -q -v

Start a queue run for just local deliveries:

Code: root@localhost# exim -ql -v

Remove a message from the queue:

Code: root@localhost# exim -Mrm <message-id> [ <message-id> ... ]

Freeze a message:

Code: root@localhost# exim -Mf <message-id> [ <message-id> ... ]

Thaw a message:

Code: root@localhost# exim -Mt <message-id> [ <message-id> ... ]

Deliver a specific message:

Code: root@localhost# exim -M <message-id> [ <message-id> ... ]

Force a message to fail and bounce:

Code: root@localhost# exim -Mg <message-id> [ <message-id> ... ]

Unthaw all frozen messages and force re-delivery : Code: root@localhost# exim -qff

Remove(delete, get rid of) all frozen messages:

Code: root@localhost# exiqgrep -z -i | xargs exim -Mrm

Remove all messages older than five days (86400 * 5 = 432000 seconds):

Code: root@localhost# exiqgrep -o 1296000 -i | xargs exim -Mrm

Freeze all queued mail from a given sender:

Code: root@localhost# exiqgrep -i -f luser@example.tld | xargs exim -Mf

View a message's headers:

Code: root@localhost# exim -Mvh <message-id>

View a message's body:

Code: root@localhost# exim -Mvb <message-id>

View a message's logs:

Code: root@localhost# exim -Mvl <message-id>

 

Bonus!

To delete all queued messages containing a certain string in the body:

Code: root@localhost# grep -lr 'a certain string' /var/spool/exim/input/ | \

               sed -e 's/^.*\/\([a-zA-Z0-9-]*\)-[DH]$/\1/g' | xargs exim -Mrm

Note that the above only delves into /var/spool/exim in order to grep for queue files with the given string, and that's just because exiqgrep doesn't have a feature to grep the actual bodies of messages. If you are deleting these files directly, YOU ARE DOING IT WRONG! Use the appropriate exim command to properly deal with the queue.

If you have to feed many, many message-ids (such as the output of an `exiqgrep -i` command that returns a lot of matches) to an exim command, you may exhaust the limit of your shell's command line arguments. In that case, pipe the listing of message-ids into xargs to run only a limited number of them at once. For example, to remove thousands of messages sent from joe@example.com:

Code: root@localhost# exiqgrep -i -f '<joe@example.com>' | xargs exim -Mrm

So..that's that. Back to top View user's profile Send private message AIM Address aledesma Site Admin

Joined: 25 Oct 2004 Posts: 78 Location: DLLSTX5

PostPosted: Sun May 21, 2006 6:29 pm Post subject: Re: Exim Cheatsheet Reply with quote fmerrill wrote:

Code: root@localhost# grep -lr 'a certain string' /var/spool/exim/input/ | \

               sed -e 's/^.*\/\([a-zA-Z0-9-]*\)-[DH]$/\1/g' | xargs exim -Mrm

basename is your friend.

Code: root@server# grep -lZ -m1 -R string /var/spool/exim/input | \

xargs -0 -n1 basename | \
xargs exim -Mrm

Smile Back to top View user's profile Send private message Send e-mail fmerrill

 

Joined: 21 Mar 2005 Posts: 46

PostPosted: Mon May 22, 2006 1:35 pm Post subject: Re: Exim Cheatsheet Reply with quote aledesma wrote: fmerrill wrote:

Code: root@localhost# grep -lr 'a certain string' /var/spool/exim/input/ | \

               sed -e 's/^.*\/\([a-zA-Z0-9-]*\)-[DH]$/\1/g' | xargs exim -Mrm

basename is your friend.

Code: root@server# grep -lZ -m1 -R string /var/spool/exim/input | \

xargs -0 -n1 basename | \
xargs exim -Mrm