Other things for Exim

Note: The following is part of a series of steps to setup an email server using Exim 4.x, with imap and webmail access. It will use winbind to get user information from an NT server. If you found this page via a search engine it may not cover what you need or you may need to start at the beginning to understand everything I have done.

The following are just some miscellaneous things I've done or discovered that relate to Exim.

(Note: These instructions reference software that is now possibly much newer with many new or different configuration options. This page is being left up for reference.)

See http://www.exim.org/ for much more information.

  1. Other sites
  2. Keeping an eye on your server
  3. Email users with their useage

1) Other sites

2) Keeping an eye on your server

Just switching to Exim and want to keep an eye on things without having an SSH session open all the time? Want to have something to calm the boss's fears that his email is not being sent out and that, yes, the dang thing is running? Well what I did was set up some php pages to tail log files, get the status of various processes, and run some statistics programs. You can download my phps here.

Use at your own risk!

The archive "mail_monitor.tar.gz" includes:

  • mail_fullstats.php: Runs eximstats on the main log file
  • mail_log.php: Tails the main, reject, and panic log files
  • mail_mainlog.php: Cats the main log file
  • mail_paniclog.php: Cats the panic log file
  • mail_queue.php: Runs mailq on two exim.conf files (MailScanner setup). Requires sudo setup
  • mail_rejectlog.php: Cats the reject log file
  • mail_stats.php: Runs eximstat from http://exim.got-there.com/forums/viewtopic.php?t=344
  • misc_log.php: Greps various other logs for certain information, such as MailScanner info
  • server_processes.php: Runs ps -Al
  • server_status.php: Runs uptime, free, df -h, and pgrep for certain processes


You may need to edit several of these files to point to the correct exim logs or to otherwise adjust for your setup. Also you may need to install certain files, such as eximstats and eximstat, and configure them if required. Remember to change rights (chmod) on the directories and files that the php scripts must access so that the user the web server runs as can read them.

Setting up sudo to allow the user apache to run mailq only on the localhost:
quick vi primer

# sudoers file.
# This file MUST be edited with the 'visudo' command as root.
# See the sudoers man page for the details on how to write a sudoers file.
# Host alias specification
Host_Alias LOCAL = localhost
# User alias specification
User_Alias WEB = apache
# Runas alias specification
Runas_Alias MAILADMIN = mail
# Cmnd alias specification
Cmnd_Alias MAILSTUFF = /usr/bin/mailq
# User privilege specification
root    ALL=(ALL) ALL

I slightly modified the eximstat (not eximstats) script to use grep instead of fgrep. This was so I could use regexps in the eximstat.strings file. My eximstat.strings file looks like:

  FROM LOCAL::: <=.*@dom\.ain
DELIVERES LOCAL::: =>.*local_delivery
DELIVERIES SHARED::: =>.*maildir_shared_folder
DELIVERIES REMOTE::: =>.*remote_smtp
RBL - Denied:::listed in (deny)
RBL - Warned:::listed in (warn)
RELAYING NOT ALLOWED:::relaying not permitted
UNKNOWN USER:::Unrouteable address
UNKNOWN SENDER:::Sender verify failed
INVALID HOSTNAME-HELO:::syntactically invalid
DEFERALS::: \=\=

Even though these scripts are simply reading log files and echoing back text, I would suggest setting up Apache to only allow internal IPs to access them. You never know when something sensitive might show up.

3) Email users with their useage

This is a bash script (I'm using v2.05b) I wrote to get each user's storage useage, their quota as set in a file that exim uses, calculate how much space they have left, and email them with that information. I keep in in /etc/cron.monthly so it runs once a month. Use and modify at your own risk as it's only my second bash script.

# This script will get the size of a users maildir,
# quota limit, how much is left, and email them with
# the information.
# Adjust the following as needed
# optional, has a Maildir that is used for
# couriers shared folders and no user is
# associated with it, so the email would bounce
# Begin script, adjust if needed
DIRS=$(find . -maxdepth 1 -type d)
for DIR in $DIRS
if [ $DIR != $SHAREDFOLDER ]; then
 # If Maildir exists
 if [ -d $DIR/$MAILDIRNAME ]; then
  # Remove ./ in front of $DIR to get username
  # Get disk usage, should return results in K
  MSIZE=$(du -s $DIR/$MAILDIRNAME/|awk '{ print $1 }')
  # Find users quota that exim uses
  USERLIMIT=$(cat $EXIMQUOTA | grep $USERSNAME | awk '{print $2}')
  # If user not specifically defined then use default
  if [ -z $USERLIMIT ]; then
   USERLIMIT=$(cat $EXIMQUOTA | grep \* | awk '{print $2}')
  # Get the numbers from userlimit
  # Convert M to K (fix if using other units)
  if [ $USERLIMITUNIT = "M" ]; then
   # To be correct use 1024 instead
   let "USERLIMITAMOUNT *= 1000"
  # How much is left
  # Email the information gathered to the user
   echo "Mail From:<$MAILFROM@$DOMAIN>
Subject:Your email storage useage
This is a regular automated message.
Your email is taking up $MSIZE K of space.
Your email limit is $USERLIMITAMOUNT K.
You have $SPACELEFT K available.
Remember that if you run out of space you will no longer be able to receive email.
quit" | exim -bs > /dev/null 2>&1
exit 0