Most of our Linux servers use Exim as the Mail Transfer Agent (MTA). Exim comes with a number of useful utilities you can use to manage the mail queue and troubleshoot email issues.

The utility you are likely to use most is exigrep. In order to use that utility you need to understand Exim’s logs, and we therefore have written a separate article about Exim log files and exigrep.

Is Exim running?

Before we dive into the utilities, let’s make sure Exim is actually running. You can do so with the command systemctl status exim or systemctl is-active exim. Or, if you are old-school you might prefer ps:

# systemctl is-active exim

# ps -C exim
  PID TTY          TIME CMD
 6746 ?        00:00:00 exim
 6807 ?        00:00:00 exim
 6871 ?        00:00:00 exim
15016 ?        00:03:32 exim

If Exim is not running your server may use another MTA. Of course, it can also be that the service is down. Running systemctl is-enabled exim will tell you if Exim is enabled on your server (see our Managing services article for more information about systemd and systemctl).

Exim configuration

Exim is a complicated piece of software. We won’t go into much detail about the configuration – contact us if you want the set-up to be changed on your server. We will give some quick pointers though.

In WHM, you find most of Exim’s configuration options under Service Configuration » Exim Configuration Manager. If anything needs to be tweaked, this is the preferred way to make changes.

If you want a summary of the current configuration then you can use the command exim -bP. As the command produces lots of output we will just filter our some interesting settings:

# exim -bP | grep -E "^(daemon_smtp_ports|message_size_limit|recipients_max)"
daemon_smtp_ports = 25 : 465 : 587
message_size_limit = 50M
recipients_max = 0

The output shows the SMTP ports on which the Exim daemon listens; the maximum size an outgoing email can be and the maximum number of recipients (0 indicates that no limit is enforced).

Viewing the mail queue

You can get basic information about all emails in the mail queue via exim -bp:

# exim -bp
 4h   3.6K 1h1Gb3-00029f-NA <> (example)

52m   2.5K 1h1adA-00FjqU-L1 <> (example)

The output shows the following information on the first line:

  • The time the email has been in the queue
  • The size of the email
  • The Exim ID
  • The sender’s email address and, if applicable, the system user

The destination of an email is shown on the subsequent lines. The second email in the above example has two recipients. A D in front of an email indicates that the email has delivered.

Counting messages

You can get a count of the number of emails in the queue by adding the -c option:

# exim -bpc

Viewing and removing emails

You can use the Exim ID to view or remove emails.

  • exim -Mvh – View the message headers
  • exim -Mvb – View the message body
  • exim -Mvc – View both the message headers and body
  • exim -Mrm – Remove (purge) the message

Searching the mail queue

You can use the exiqgrep utility to retrieve specific emails in the mail queue. It has got various useful options:

  • -f – Match the sender’s email address
  • -r – Match the recipient’s email address
  • -y – Match messages younger than [seconds]
  • -o – Match messages older than [seconds]
  • -z – Match frozen messages
  • -x – Match non-frozen messages
  • -c – Display a match count
  • -i – Display message IDs only

This gives you lots of options for grepping the mail queue. For instance, if you see lots of emails from in the queue you can quickly get more information:

# exiqgrep -cf
15 matches out of 38 messages

# exiqgrep -zcf
0 matches out of 38 messages

# exiqgrep -xcf
15 matches out of 38 messages

The output shows that there are 15 emails from in the queue and that none of the emails has been frozen.

If you are sure that certain emails can be deleted then you can pipe the output of a exiqgrep -i command to exim -Mrm. For instance, to delete all emails in the queue with the sender you can use this command:

# exiqgrep -if | xargs exim -Mrm

Summary view

Exim comes with a few other useful utilities. exiqsumm is a script that reads the output of exim -bp and produces a summary. You can’t run exiqsumm on its own – instead you can pipe the output of exim commands to the utility:

# exim -bp | exiqsumm -c

Count  Volume  Oldest  Newest  Domain
-----  ------  ------  ------  ------
   21   259KB     23h     52m

Here, we added the -c option to sort the domains by the number of emails. This can be useful way to quickly identify problematic domains.

Checking redeliveries

Exim will try to deliver emails that are stuck in the queue at a later date. You can get more information about these redelivery attempts via the exinext utility:

# exinext
Transport: []:1j15Dg-005dkr-Ag error -18: []: Remote host closed connection in response to end of data
  first failed: 11-Feb-2020 18:42:18
  last tried:   11-Feb-2020 19:43:08
  next try at:  11-Feb-2020 19:58:08

Often the utlity won’t produce any meaningful output though: it only works if there is a specific error.

Grepping logs

As mentioned in the introduction, we haven’t touched on the most-used utility yet: exigrep. This utility works much like grep but it is designed specifically to find information in the Exim logs. We have a separate article about Exim’s log files and exigrep.