Useful Exim Commands

Useful Exim Commands

What is exim?

Exim is a message transfer agent (MTA) developed at the University of Cambridge for use on Unix systems connected to the Internet. It is freely available under the terms of the GNU General Public Licence. In style it is similar to Smail 3, but its facilities are more general. There is a great deal of flexibility in the way mail can be routed, and there are extensive facilities for checking incoming mail. Exim can be installed in place of Sendmail, although the configuration of Exim is quite different.


Useful Exim Commands

Here's how you could manage exim via your terminal.

- Check size of mail queue:

exim -bpc

- Check messages in the queue:

exim -bp

- Get structured recap of the messages in the queue:

exim -bp | exiqsumm

- Remove emails sent from

exiqgrep -i -f | xargs exim -Mrm

- Remove emails sent to

exiqgrep -ir | xargs exim -Mrm

- Number of emails per email account:

exim -bpr | grep "<" | awk {'print $4'} | cut -d "<" -f 2 | cut -d ">" -f 1 | sort -n | uniq -c | sort -n

- Check the exim log for emails generated from folders/scripts (cwd):

grep "cwd=/home" /var/log/exim_mainlog | grep -v Cron | awk '{for(i=1;i<=10;i++){print $i}}' | sort | uniq -c | grep cwd | sort -n
awk '{ if ($0 ~ "cwd" && $0 ~ "home") {print $3} }' /var/log/exim_mainlog | sort | uniq -c | sort -nk 1
grep 'cwd=/home' /var/log/exim_mainlog | awk '{print $3}' | cut -d / -f 3 | sort -bg | uniq -c | sort -bg

- Find any emails generated by a PHP script currently in the mail queue:

egrep -R "X-PHP-Script"  /var/spool/exim/input/*

- Top 50 usage:

eximstats -ne -nr /var/log/exim_mainlog

- IPs connected on port 25:

netstat -plan | grep :25 | awk {'print $5'} | cut -d: -f 1 | sort | uniq -c | sort -nk 1

- "Nobody" spamming:

ps -C exim -fH ewww | awk '{for(i=1;i<=40;i++){print $i}}' | sort | uniq -c | grep PWD | sort -n

- Mail queue summary:

exim -bpr | exiqsumm -c | head

- Shows messages headers:

exim -Mvh messageid 

- Body of the message:

exim -Mvb message id 

Hope that this helps :)