Managing Exim via the command line is straightforward. You can manage mail queues, find and remove specific user messages, and perform various other tasks. All sent emails are logged in the directory /var/spool/exim/msglog, with each record having an ID number corresponding to the message ID. In the /var/spool/exim/input directory, records are marked with -H (header) and -D (message content). Each sent message creates three files. Here’s a guide to working with these directories and commands:
Queue Management Commands
- Count Messages in the Queue:
- Print a Listing of Messages in the Queue (including time queued, size, message-id, sender, recipient):
- Print a Summary of Messages in the Queue (including count, volume, oldest, newest, domain, and totals):
- Print What Exim is Currently Doing:
- Test How an Email Address is Pointed:
- Run a Pretend SMTP Transaction from the Command Line (displays Exim’s checks, ACLs, and filters without actual delivery):
- Display All of Exim’s Configuration Settings:
Searching the Queue with exiqgrep
exiqgrep
is a utility for searching through the queue:
- Search the Queue for Messages from a Specific Sender:
- Search the Queue for Messages for a Specific Recipient/Domain:
- Print Messages Older Than the Specified Number of Seconds (e.g., messages older than 1 day):
- Print Messages Younger Than the Specified Number of Seconds (e.g., messages less than an hour old):
- Match Messages by Size with a Regex (e.g., 700-799 bytes):
Match Only Frozen Messages or Unfrozen Messages:
Frozen messages:
> exiqgrep -z -i
Unfrozen messages:
> exiqgrep -x -i
Print a Count of Messages Matching the Search Criteria:
- Print Just the Message-ID of the Entire Queue:
Managing the Queue
- Start a Queue Run:
- Start a Queue Run for Local Deliveries Only:
- Remove a Message from the Queue:
exim -Mrm <message-id> [ <message-id> ... ]
- Freeze a Message:
exim -Mf <message-id> [ <message-id> ... ]
- Throw a Message:
exim -Mt <message-id> [ <message-id> ... ]
- Deliver a Message, Regardless of Its Frozen Status or Retry Time:
exim -M <message-id> [ <message-id> ... ]
- Deliver a Message Only If the Retry Time Has Been Reached:
exim -Mc <message-id> [ <message-id> ... ]
- Force a Message to Fail and Bounce as "Cancelled by Administrator":
exim -Mg <message-id> [ <message-id> ... ]
- Remove All Frozen Messages:
exiqgrep -z -i | xargs exim -Mrm
Remove All Messages Older Than Five Days (86400 * 5 = 432000 seconds):
> exiqgrep -o 432000 -i | xargs exim -Mrm
Freeze All Queued Mail from a Given Sender:
> exiqgrep -i -f luser@example.tld | xargs exim -Mf
View a Message’s Headers:
> exim -Mvh <message-id>
View a Message’s Body:
> exim -Mvb <message-id>
View a Message’s Logs:
> exim -Mvl <message-id>
Digging Into Exim Mail Logs with Exigrep
is useful for finding specific log entries spanning multiple lines:
- Search for Messages Sent from a Particular IP Address:
exigrep '<= .* [12.34.56.78] ' /path/to/exim_log
- Search for Messages Sent to a Particular IP Address:
exigrep '=> .* [12.34.56.78] ' /path/to/exim_log
- Generate and Display Exim Stats from a Logfile:
eximstats /path/to/exim_mainlog
- Same as Above, with Less Verbose Output:
eximstats -ne -nr -nt /path/to/exim_mainlog
- Delete All Queued Messages Containing a Certain String in the Body:
grep -lr 'a certain string' /var/spool/exim/input/ | sed -e 's/^.\/([a-zA-Z0-9-])-[DH]$/\1/g' | xargs exim -Mrm
For more information, visit: