Howto: Configure Exim as SMTP Relay

Linux
Howto
Published

November 6, 2024

Modified

November 7, 2024

An SMTP relay configuration is frequently employed in enterprise environments, allowing organizations to maintain control over their email communications and ensure reliable delivery through a central mail service infrastructure.

Exim1 is a Mail Transfer Agent (MTA) that facilitates the sending and receiving of email messages. In the following configuration, Exim is set up as a simple relay, forwarding messages to a central mail service. In this role, Exim serves as an intermediary in the email delivery process, relaying messages to a so called smart host.

Installation

The Fedora project provides Exim RPM packages in EPEL:

# make the EPEL repository available
dnf install -y epel-release

# install Exim and show version information 
dnf install -y exim

# install a mail client for testing
dnf install -y s-nail

Configuration

Exim uses a single configuration2 file /etc/exim/exim.conf.

# backup the main configuration file
cp /etc/exim/exim.conf /etc/exim/exim.conf.backup

# modify the Exim configuration...
$EDITOR /etc/exim/exim.conf ; exim -bV
# ...verify the configuration file is syntactically correct

# restart the service after configuration changes
systemctl restart exim.service

After modifications to this file use exim -bV to run a syntax check. The configuration file contains a dedicated section about a smart host configuration:

# note following section in the default configuration
>>> grep 'smarthost:' -A4 /etc/exim/exim.conf 
smarthost:
  driver = manualroute
  domains = ! +local_domains
  transport = smarthost_smtp
  route_data = ROUTER_SMARTHOST

Configure the ROUTER_SMARTHOST macro by providing the name of the local SMTP server that accepts to route email messages:

# alternative to editing the file manually
sed -i "s/^# ROUTER_SMARTHOST=.*/ROUTER_SMARTHOST=$mail_server/g" /etc/exim/exim.conf

Usage

exim -bt runs the address testing mode using a recipient address. Once the SMTP relay configuration is confirmed, send a mail to verify the functionality:

# how exim will route a given address
exim -bt $mail_address

# send a mail
echo "body" | mail -s "subject" -r root@$(hostname -f) $mail_address

Some operational commands for Exim:

# what is exim doing ...count of the messages in the queue
exiwhat
exim -bpc

# print configuration setting
exim -bP

# listing of the messages in the queue
exim -bp
exim -bp | exiqsumm