CentOS: install and configure SMTP server

Step 1: Install Exim
Install Exim from the CentOS repository using the following command line:

sudo yum install exim

After the installation is complete, you can check the installed Exim version with the command:

exim --version


[root@tutorialspots ~]# exim --version
Exim version 4.91 #2 built 22-Aug-2018 14:16:00
Copyright (c) University of Cambridge, 1995 - 2018
(c) The Exim Maintainers and contributors in ACKNOWLEDGMENTS file, 2007 - 2018
Berkeley DB: Berkeley DB 5.3.21: (May 11, 2012)
Support for: crypteq iconv() IPv6 PAM Perl Expand_dlfunc OpenSSL Content_Scanning DKIM DNSSEC Event OCSP PRDR TCP_Fast_Open
Lookups (built-in): lsearch wildlsearch nwildlsearch iplsearch cdb dbm dbmjz dbmnz dnsdb dsearch ldap ldapdn ldapm nis nis0 nisplus passwd sqlite
Authenticators: cram_md5 cyrus_sasl dovecot gsasl plaintext spa tls
Routers: accept dnslookup ipliteral manualroute queryprogram redirect
Transports: appendfile/maildir/mailstore/mbx autoreply lmtp pipe smtp
Malware: f-protd f-prot6d drweb fsecure sophie clamd avast sock cmdline
Fixed never_users: 0
Configure owner: 0:0
Size of off_t: 8
Configuration file is /etc/exim/exim.conf

Step 2: Configure Exim
Configure Exim via configuration file /etc/exim/exim.conf or /etc/exim/exim4.conf (you can see in step 1). You can edit this file using a text editor such as vi or nano.

Add disable_ipv6 = true at the top of config file to disable ipv6 if need

After editing the configuration, you need to restart Exim to apply the changes:

sudo systemctl restart exim

Step 3: Install and configure DKIM
Install opendkim:

sudo yum install opendkim

[root@tutorialspots ~]# sudo yum install opendkim
Loaded plugins: fastestmirror
Loading mirror speeds from cached hostfile
 * base: mirror.viettelcloud.vn
 * epel: repo.jing.rocks
 * extras: mirror.viettelcloud.vn
 * remi-php56: ftp.riken.jp
 * remi-safe: ftp.riken.jp
 * rpmforge: kartolo.sby.datautama.net.id
 * updates: mirror.viettelcloud.vn
http://yum.mariadb.org/10.0/centos7-amd64/repodata/repomd.xml: [Errno 14] HTTP Error 404 - Not Found
Trying other mirror.
To address this issue please refer to the below wiki article


If above article doesn't help to resolve this issue please use https://bugs.centos.org/.

Resolving Dependencies
--> Running transaction check
---> Package opendkim.x86_64 0:2.11.0-0.1.el7 will be installed
--> Processing Dependency: libopendkim(x86-64) = 2.11.0-0.1.el7 for package: opendkim-2.11.0-0.1.el7.x86_64
--> Processing Dependency: libbsd.so.0(LIBBSD_0.0)(64bit) for package: opendkim-2.11.0-0.1.el7.x86_64
--> Processing Dependency: libbsd.so.0()(64bit) for package: opendkim-2.11.0-0.1.el7.x86_64
--> Processing Dependency: libmilter.so.1.0()(64bit) for package: opendkim-2.11.0-0.1.el7.x86_64
--> Processing Dependency: libopendbx.so.1()(64bit) for package: opendkim-2.11.0-0.1.el7.x86_64
--> Processing Dependency: libopendkim.so.11()(64bit) for package: opendkim-2.11.0-0.1.el7.x86_64
--> Running transaction check
---> Package libbsd.x86_64 0:0.12.2-1.el7 will be installed
--> Processing Dependency: libmd.so.0(LIBMD_0.0)(64bit) for package: libbsd-0.12.2-1.el7.x86_64
--> Processing Dependency: libmd.so.0()(64bit) for package: libbsd-0.12.2-1.el7.x86_64
---> Package libopendkim.x86_64 0:2.11.0-0.1.el7 will be installed
---> Package opendbx.x86_64 0:1.4.6-6.el7 will be installed
---> Package sendmail-milter.x86_64 0:8.14.7-6.el7 will be installed
--> Running transaction check
---> Package libmd.x86_64 0:1.1.0-1.el7 will be installed
--> Finished Dependency Resolution

Dependencies Resolved

 Package                Arch          Version                 Repository   Size
 opendkim               x86_64        2.11.0-0.1.el7          epel        222 k
Installing for dependencies:
 libbsd                 x86_64        0.12.2-1.el7            epel        130 k
 libmd                  x86_64        1.1.0-1.el7             epel         41 k
 libopendkim            x86_64        2.11.0-0.1.el7          epel         75 k
 opendbx                x86_64        1.4.6-6.el7             epel         46 k
 sendmail-milter        x86_64        8.14.7-6.el7            base         71 k

Transaction Summary
Install  1 Package (+5 Dependent packages)

Total download size: 585 k
Installed size: 1.4 M
Is this ok [y/d/N]: y
Downloading packages:
(1/6): libbsd-0.12.2-1.el7.x86_64.rpm                      | 130 kB   00:01
(2/6): libmd-1.1.0-1.el7.x86_64.rpm                        |  41 kB   00:00
(3/6): libopendkim-2.11.0-0.1.el7.x86_64.rpm               |  75 kB   00:00
(4/6): opendbx-1.4.6-6.el7.x86_64.rpm                      |  46 kB   00:00
(5/6): opendkim-2.11.0-0.1.el7.x86_64.rpm                  | 222 kB   00:00
(6/6): sendmail-milter-8.14.7-6.el7.x86_64.rpm             |  71 kB   00:00
Total                                              164 kB/s | 585 kB  00:03
Running transaction check
Running transaction test
Transaction test succeeded
Running transaction
  Installing : libmd-1.1.0-1.el7.x86_64                                     1/6
  Installing : libbsd-0.12.2-1.el7.x86_64                                   2/6
  Installing : libopendkim-2.11.0-0.1.el7.x86_64                            3/6
  Installing : sendmail-milter-8.14.7-6.el7.x86_64                          4/6
  Installing : opendbx-1.4.6-6.el7.x86_64                                   5/6
  Installing : opendkim-2.11.0-0.1.el7.x86_64                               6/6
  Verifying  : opendbx-1.4.6-6.el7.x86_64                                   1/6
  Verifying  : libbsd-0.12.2-1.el7.x86_64                                   2/6
  Verifying  : sendmail-milter-8.14.7-6.el7.x86_64                          3/6
  Verifying  : libopendkim-2.11.0-0.1.el7.x86_64                            4/6
  Verifying  : opendkim-2.11.0-0.1.el7.x86_64                               5/6
  Verifying  : libmd-1.1.0-1.el7.x86_64                                     6/6

  opendkim.x86_64 0:2.11.0-0.1.el7

Dependency Installed:
  libbsd.x86_64 0:0.12.2-1.el7                libmd.x86_64 0:1.1.0-1.el7
  libopendkim.x86_64 0:2.11.0-0.1.el7         opendbx.x86_64 0:1.4.6-6.el7
  sendmail-milter.x86_64 0:8.14.7-6.el7


Once installed, you need to generate a key pair for DKIM:

sudo opendkim-genkey -s -d

example: sudo opendkim-genkey -s postmaster -d tutorialspots.com

This command will generate 2 files in current directory: postmaster.private and postmaster.txt

Move the private key file into the folder /etc/opendkim/keys

sudo mv postmaster.private /etc/opendkim/keys

Add Exim user to group opendkim:

sudo usermod -aG opendkim exim

Chown private key:
chown opendkim:opendkim /etc/opendkim/keys/postmaster.private

Edit the DKIM configuration file /etc/opendkim.conf:

sudo nano /etc/opendkim.conf

Add or edit the following lines:

Domain                  tutorialspots.com
KeyFile                 /etc/opendkim/keys/postmaster.private
Selector                postmaster

Edit the Exim configuration file to use DKIM:

sudo nano /etc/exim/exim.conf

Add the following line to the section TRANSPORT CONFIGURATION:

add after:

  driver = smtp
  message_size_limit = ${if > {$max_received_linelength}{998} {1}{0}}
  dkim_domain = tutorialspots.com
  dkim_selector = postmaster
  dkim_private_key = /etc/opendkim/keys/postmaster.private

Restart Exim and opendkim to apply the changes:

sudo systemctl restart exim opendkim

Step 4: Configure DNS
Finally, you need to add the DKIM record to your domain’s DNS configuration file.

Open file postmaster.txt to see content:

[root@tutorialspots ~]# cat postmaster.txt
postmaster._domainkey   IN      TXT     ( "v=DKIM1; k=rsa; "
          "p=MIGfMA0GCSqGSIb3DQEBAQUAA4GNADCBiQKBgQDr1bP/ttIeGV/G2Tcqoci0HrbfGP/J4ghANKnrDKaqRO0UNXzo8SB7MaZ3NgK5zY0vk0BqCbs5buJxotpEpjDD8gwnWjqaZZwnKmoL9ZT8G9D24WyjlEhp3QNx6TA8nywpnT7KJQqrfyI/71TmJdzQIKq3HMABJhmVf1Y2/ZnzqQIDAQAB" )  ; ----- DKIM key postmaster for tutorialspots.com

Here’s an example of how to add a DKIM record to DNS:

postmaster._domainkey.tutorialspots.com. IN TXT "p=<public key>"

Replace with the content of the file postmaster.txt .

Step 5: SPF configuration:
Add SPF Record to DNS :
Log in to your domain’s DNS admin account. Usually through the administration interface of the domain name provider or DNS service you are using.
Add a new TXT record with the following content:

v=spf1 a:mail.yourdomain.com ip4:<server_ip> include:_spf.google.com ~all

v=spf1 a:mail.yourdomain.com ip4: include:_spf.google.com ~all

Save changes.

read more about SPF: https://support.google.com/a/answer/10685031?sjid=14440567733282704103-AP


Verify SMTP server

[root@tutorialspots ~]# telnet 25
Connected to
Escape character is '^]'.
220 google.com ESMTP Exim 4.91 Mon, 29 Apr 2024 20:06:14 +0700


yum install mailx

echo "Test mail from EXIM" | mail -s "Test EXIM" -f "postmaster@yourdomain.com" youremail@gmail.com

Leave a Reply