Last updated:
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. That’s quite a large topic, and we therefore have a separate article about Exim log files and exigrep.
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 active # 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 then your server may be using 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 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 also 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).
You can get basic information about emails in the mail queue via exim -bp
:
# exim -bp ... 52m 2.5K 1h1adA-00FjqU-L1 <mail@example.net> (example) D support@catalyst2.com example@example.com ...
The first line shows the following information:
The destination of an email is shown on the subsequent lines. There are two recipients for our example email: support@catalyst2.com and example@example.com. The letter D
in front of the first email address indicates that the email has been delivered. So, in this case the email is sitting in the queue because it hasn’t yet been delivered to example@example.com.
You can get a count of the number of emails in the queue by adding the -c
option:
# exim -bpc 42
You can use the Exim ID to view or remove emails. For instance, you can view the headers using exim -Mvh
and exim -Mvb
to view the body. The command to remove an individual email is exim -Mrm
You can use the exiqgrep
utility to retrieve specific emails in the mail queue. It has got various useful options. The following commands all match specific characteristics:
-f
– The sender’s email address-r
– The recipient’s email address-y
– Messages younger than [seconds]-o
– Messages older than [seconds]-z
– Frozen messages-x
– Non-frozen messagesIn addition, you also got options for displaying specific information:
-c
– Display a match count-i
– Display message IDs onlyThis gives you lots of options for grepping the mail queue. For instance, if you see lots of emails from me@example.net in the queue then you can quickly get more information:
# exiqgrep -cf me@example.net 15 matches out of 38 messages # exiqgrep -zcf me@example.net 0 matches out of 38 messages # exiqgrep -xcf me@example.net 15 matches out of 38 messages
The output shows that there are 15 emails from me@example.net in the queue and that none of the emails are 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 from me@example.net you can use this command:
# exiqgrep -if me@example.net | xargs exim -Mrm
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 example.net ...
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.
Exim tries to deliver emails that are stuck in the queue at a later date. You can get more information about the delivery attempts via the exinext
utility:
# exinext example@example.com Transport: mail.example.com [11.22.33.44/NULL]:1j15Dg-005dkr-Ag error -18: H=mail.example.com [11.22.33.44]: Remote host closed connection in response to end of data first failed: 11-Apr-2021 18:42:18 last tried: 11-Apr-2021 19:43:08 next try at: 11-Apr-2021 19:58:08
Often the utility doesn’t produce any meaningful output though: it only works if there is a specific error.
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.