Page 1 of 1

[Knowledge] Lists of Exim Mail Server Commands

Posted: Tue Sep 11, 2018 6:33 pm
by xorro
Today I’ll post bunch of exim mail server commands to check mail queue, remove mails and grep/search email log. Exim is a mail transfer agent which is used on Unix-like operating systems for sending,receiving and routing the email messages. Exim is a free software distributed under the terms of the General Public License (GNU), and it aims to be a general and flexible mailer with extensive facilities for checking incoming mails. The mail transfer agent exim is developed in 1995 by Philip Hazel at the University of Cambridge.

If you’re using VestaCP or other similar configuration all exim logs can be found under

Code: Select all

/var/log/exim
/var/log/exim/main.log
1. To get counted message in the queue:

Code: Select all

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

Code: Select all

exim -bp
3. Print a summary of messages in the queue (count, volume, oldest, newest, domain, and totals):

Code: Select all

exim -bp | exiqsumm
4. Print what Exim is doing right now:

Code: Select all

exiwhat
5. Testing how e-mail address is pointed:
6. Run a pretend SMTP transaction from the command line, as if it were coming from the given IP address. This will display Exim’s checks, ACLs, and filters as they are applied. The message will NOT actually be delivered:

Code: Select all

exim -bh XXX.XXX.XX.XX
7. Display all of Exim’s configuration settings:

Code: Select all

exim -bP
Searching the queue with exiqgrep

Exim includes a utility that is quite nice for grepping through the queue, called exiqgrep.

1. Use -f to search the queue for messages from a specific sender:

Code: Select all

exiqgrep -f @domaincom
2. Use -r to search the queue for messages for a specific recipient/domain:

Code: Select all

exiqgrep -r @domain.com
3. Use -o to print messages older than the specified number of seconds. For example, messages older than 1 day:

Code: Select all

exiqgrep -o 86400 [...]
4. Use -y to print messages that are younger than the specified number of seconds. For example, messages less than an hour old:

Code: Select all

exiqgrep -y 3600 [...]
5. Use -s to match the size of a message with a regex. For example, 700-799 bytes:

Code: Select all

exiqgrep -s '^7..$' [...]
Use -z to match only frozen messages, or -x to match only unfrozen messages. There are also a few flags that control the display of the output.

6. Use -i to print just the message-id as a result of one of the above two searches:

Code: Select all

exiqgrep -i [ -r | -f ] ...
7. Use -c to print a count of messages matching one of the above searches:

Code: Select all

exiqgrep -c ...
8. Print just the message-id of the entire queue:

Code: Select all

exiqgrep -i
Managing the queue

1. Start a queue run

Code: Select all

exim -q -v
2. Start a queue run for just local deliveries:

Code: Select all

exim -ql -v
3. Remove a message from the queue:

Code: Select all

exim -Mrm <message-id> [ <message-id> ... ]
4. Freeze a message:

Code: Select all

exim -Mf <message-id> [ <message-id> ... ]
5. Throw a message:

Code: Select all

exim -Mt <message-id> [ <message-id> ... ]
6. Deliver a message, whether it’s frozen or not, whether the retry time has been reached or not:

Code: Select all

exim -M <message-id> [ <message-id> ... ]
7. Deliver a message, but only if the retry time has been reached:

Code: Select all

exim -Mc <message-id> [ <message-id> ... ]
8. Force a message to fail and bounce as “cancelled by administrator”:

exim -Mg <message-id> [ <message-id> ... ]

9. Remove all frozen messages:

Code: Select all

exiqgrep -z -i | xargs exim -Mrm
10. Remove all messages older than five days (86400 * 5 = 432000 seconds):

Code: Select all

exiqgrep -o 432000 -i | xargs exim -Mrm
11. Freeze all queued mail from a given sender:

Code: Select all

exiqgrep -i -f [email protected] | xargs exim -Mf
12. View a message’s headers:

Code: Select all

exim -Mvh <message-id>
13. View a message’s body:

Code: Select all

exim -Mvb <message-id>
14. View a message’s logs:

Code: Select all

exim -Mvl <message-id>
Digging Into Exim Mail Logs With Exigrep

One single mail transaction will span multiple lines in the file, and not every line will have the search string you are looking for. The exigrep command works around this problem by finding your search string in transactions, and then helpfully gathering every log entry into separate, complete transactions.

1. Search for messages sent from a particular IP address:

Code: Select all

exigrep '<= .* \[112.225.12.12\] ' /path/to/exim_log
2. Search for messages sent to a particular IP address:

Code: Select all

exigrep '=> .* \[112.225.12.12\] ' /path/to/exim_log
This is how you search for outgoing messages with the “=>” symbol that are sent to “[email protected]”. The pipe to grep for the “<=” symbol will only match lines containing information on the sender, the From address, the sender’s IP address, the message size, the message ID, and the subject line if you have enabled logging the subject.

3. Generate and display Exim stats from a logfile:

Code: Select all

eximstats /path/to/exim_mainlog
4. Same as above, with less verbose output:

Code: Select all

eximstats -ne -nr -nt /path/to/exim_mainlog
5.To delete all queued messages containing a certain string in the body:

Code: Select all

grep -lr 'a certain string' /var/spool/exim/input/ | \sed -e 's/^.*\/\([a-zA-Z0-9-]*\)-[DH]$/\1/g' | xargs exim -Mrm