Exim4 is a lightweight and commonly used MTA on servers; This is the default MTA under Debian. Its configuration is quite easy, but beyond the configuration itself, it can be saving to know the main commands to diagnose problems and to administer the server. Let’s see it all.

In order to put it right, and because it’s often a little blurry in our minds, let’s quickly review the various organs that come into play in the functioning of email.

[easy-tweet tweet=”Essential controls to tame Exim4″ user=”@Wesharethis” hashtags=”#Exim4, #server ” url=” https://wesharethis.com/2017/08/essential-controls-to-tame-exim4/ ‎” template=”light”]

The different parts of the email

Mail Transfer Agent (MTA)
It handles the transmission of messages to another machine on the network and accepts messages to its own users. In common use, when you send an e-mail, the MTA of your machine will contact the ISP of your ISP, who will send the mail itself to the ISP of the correspondent’s ISP.
Mail Delivery Agent (MDA)
It handles the receiving part of the email. When the MTA accepts messages to its users, it sends them to the MDA, which will sort them and place them in the correct inboxes.
Mail Retrieval Agent (MRA)
We agree that the mailbox itself is not on your desktop but on a server. The mission of the MRA is therefore to repatriate the mails on your machine.
Mail User Agent (MUA)
It is the client “the browser of the mail”, it is in charge to properly display the emails so that you can read them, and format the ones that you write before passing them to the MTA.
Mail Submission Agent (MSA)
It is an internal program in the MUA, it is actually the link between the MUA and the MTA. It is a simple relay.
For all this little world to communicate, they have to agree on protocols to use. The two protocols used are SMTP and POP (or IMAP) protocols. MTAs communicate with each other via the SMTP protocol.

Be careful, however, the mailbox is not necessarily configured to be connected via POP or IMAP. This requires a POP or IMAP server. To make its box accessible through its protocols is called “expose the box”.

Installing exim4

Apt-get install exim4- get install exim4
Dpkg-reconfigure exim4-config- reconfigure exim4 - config

For the reconfigure, you will have an interactive window that will open. My servers being web servers, I select “direct distribution by smtp” (which allows to send mails without configuring the reception). Then I leave the default settings except for the name of the system email.

By default, the entire hostname is configured. For example on my server en1.erdt.net , the field is prefilled with “en1.erdt.me”, or as explained in the window, this field must match the FQDN , but I remove the name of the server, Because the local emails are for example contact@xxx.net and not contact@en1.xxx.net.

Once all this is set up, we test the sending of an email to confirm that everything works properly.

Echo "This is a test." | Mail -s Testing mail@mymail.net
"This is a test." | Mail - s Testing  mail @ mymail . net

Exim is also able to send emails via a smarthost, that is to say an intermediate server which will be responsible for communicating directly with the recipient’s MTA. This can be particularly useful in cases where port 25 is blocked by your ISP. This configuration is explained in the Debian docs .

Exim Commands

Each email consists of three files in Exim. One in /var/spool/exim/msglogwhich contains the logs linked to the message and which carries as name the message-id, the other two are in /var/spool/exim/inputand takes as name the message-id plus a suffix indicating whether it is the header (-H) or Of the message body (-D).

About the Message-ID, it is composed of alphanumeric characters and take the following form: XXXXXX-YYYYYY-ZZ.

Current orders

Shows what Exim is doing.
exim -bP
View the server configuration.
Simply display the e-mail queue. It is an alias ofexim -bp
exim -bpc
Counts the number of messages in the queue.
exim -bp | exiqsumm
This command displays by domain, the number of messages in the queue, the volume per destination domain concerned, and for each of them the oldest and most recent email.

Count Volume Oldest Newest Domain  Volume Oldest Newest Domain      
----- ------ ------ ------ ----------- ------ ------ ------ ------        
   11 495KB 14h 14h gmail.com11 495KB 14h 14h   gmail . com             
   20 900KB 14h 14h homtail.com20 900KB 14h 14h   homtail . com             
  154 6930KB 14h 14h yahoo.com154 6930KB 14h 14h   yahoo . com            
exim -bt mymail@domain.net
Shows how Exim intends to route the message.

Search in the mail

Exim exposes a very handy tool I named exiqgrep. This allows you to perform regular expression searches directly in the mail queue.

exiqgrep -f [user]@domain

We can easily find the set of messages sent by a precise email address or a domain.

exiqgrep -r [user]@domain
Here we are doing the very opposite of what we have done in the line above. E-mails are searched by recipient.
exiqgrep -o 120
We are looking for all messages sent more than 120 seconds ago.
exiqgrep -y 120
We are looking for all messages sent here less than 120 seconds.

In addition to the above parameters, it is also possible to restrict the search using the parameters -i-zand -xwhich allow respectively to display only the ids of the messages, frozen (frozen) and non- frozen messages .

Manage queue AKA Exim queue

exim -Mf message-id
Freezer a message.
exim -Mt message-id
Unfreeze a message.
exim -M message-id
Force to send the message.
exim -Mvl message-id
See logs related to the message.
exim -Mvh message-id
Display message headers.
exim -Mvb message-id
Show the body of the message.
exim -Mrm message-id
Delete the message from the queue.
exim -qf
Force sending messages in frozen state .
exim -qff
Force sending all messages.
exim -Mar message-id address [address …]
Add recipients to a message.
exim -Mes message-id address
Change the sender of the email.

As a bonus, here are some advanced commands:

# List all sender messages grouped by sender
Exim -bpr | Grep -Eo "<[^] * @ [^] *>" | Sort | Uniq -c- bpr | Grep - Eo "<[^] * @ [^] *>" | Sort | Uniq - c  
# List all messages in the queue grouped by recipient# List all messages in the queue grouped by recipient
Exim -bpr | Grep -Eo "^ \ s * [^] * @ [^] * $" | Sort | Uniq -c- bpr | Grep - Eo "^ \ s * [^] * @ [^] * $" | Sort | Uniq - c  
# Delete all messages longer than 12 hours
Exiqgrep - o 43000 - i | Xargs exim - Mrm 
# Remove all frozen messages from the queue
Exiqgrep - z - i | Xargs exim - Mrm
# Delete all messages from a particular sender
Exiqgrep - i - f [ user ] @domain | Xargs exim - Mrm 
# Delete all messages of more than 12 hours from a particular sender
Exiqgrep - o 43000 - i - f [ user ] @domain | Xargs exim - Mrm  

# Delete all messages containing "bla bla bla" in their content
Grep - lr 'bla bla bla' / var / spool / exim / input / | Sed - e 's / ^. \ / \ ([A-zA-Z0-9 -] * \) - [DH] $ / \ 1 / g' | Xargs exim - Mrm   

This should help you in your use of Exim! If you have remarks or additional orders, do not hesitate to let me know.


Am a tech geek.. Do you wanna know more about me..? My contents will do tell you.

Pin It