Sendmail is a feature-rich MTA (Mail Transfer Agent) uses SMTP protocol for sending mail. Though Sendmail has been replaced by postfix in modern RHEL versions it is widely used in RHEL 5 or its earlier version. Sendmail is recommended by most of the system administrator as an MTA(Mail transfer agent) server over other MTAs.
Prerequisites Before you Install Sendmail Server on Centos 7
Highly recommended to have root privileges in order to perform the below steps:
Add the centos 7 EPEL repositories, open terminal and paste the below command:
sudo yum install epel-release
Install Sendmail with dependency from yum package manager
sudo yum install sendmail sendmail-cf m4
(Note: m4 is a macro processor you need to use to compile Sendmail configuration file. )
Once the installation is done, you will be getting output like this:
Transaction Summary =================================================
Install 3 packages
Total download size: 1.2 M
Installed size: 3.1 M
Is this ok [y/d/N]: y
(1/3): sendmail-cf-8.14.7-5.el7.noarch.rpm | 186 kB 00:00:00
(2/3): m4-1.4.16-10.el7.x86_64.rpm | 256 kB 00:00:00
(3/3): sendmail-8.14.7-5.el7.x86_64.rpm | 736 kB 00:00:01
Total 888 kB/s | 1.2 MB 00:00:01
Running transaction check
Running transaction test
Transaction test succeeded
Installing : m4-1.4.16-10.el7.x86_64 1/3
Installing : sendmail-8.14.7-5.el7.x86_64 2/3
Installing : sendmail-cf-8.14.7-5.el7.noarch 3/3
Verifying : sendmail-8.14.7-5.el7.x86_64 1/3
Verifying : sendmail-cf-8.14.7-5.el7.noarch 2/3
Verifying : m4-1.4.16-10.el7.x86_64 3/3
m4.x86_64 0:1.4.16-10.el7 sendmail.x86_64 0:8.14.7-5.el7 sendmail-cf.noarch 0:8.14.7-5.el7
rpm -qa | grep sendmail
Step 3: Configure sendmail server
Before directly edit /etc/mail/sendmail.mc for configuration we need to understand important file existence in /etc/mail directory.
- access: allowing or denying other systems to use Sendmail for outbound emails.
- domaintable: used for domain name mapping for Sendmail.
- local-host-names: used to define an alias for a host.
- mailertable: used to override routing for particular domains.
- virtusertable: allowing multiple virtual domains to be hosted on one machine.
Make the following changes in sendmail.mc file below is the command:
Note: Set your SMTP hostname above
#Add the below two lines in your sendmail.mc file to listen on port 465 and 587:
define(`RELAY_MAILER_ARGS', `TCP $h 587')dnl define(`ESMTP_MAILER_ARGS', `TCP $h 587')dnl
#Uncomment the below lines:
TRUST_AUTH_MECH(`EXTERNAL DIGEST-MD5 CRAM-MD5 LOGIN PLAIN')dnl define(`confAUTH_MECHANISMS', `EXTERNAL GSSAPI DIGEST-MD5 CRAM-MD5 LOGIN PLAIN')dnl
#Add the below lines:
FEATURE(`authinfo', `hash /etc/mail/auth/client-info.db')dnl FEATURE(`access_db', `hash -T<TMPF> -o /etc/mail/access.db')dnl DAEMON_OPTIONS(`Port=smtp, Name=MTA')dnl
#Uncomment for Sendmail to listen on port 587
DAEMON_OPTIONS(`Port=submission, Name=MSA, M=Ea')dnl
#Uncomment for sendmail to listen on port 587
DAEMON_OPTIONS(`Port=smtps, Name=TLSMTA, M=s')dnl
#Mention your domain and uncomment
Save and exit the file.
Step 4: Make Auth Directory
By assigning proper permission to make auth directory inside /etc/mail
sudo mkdir /etc/mail/auth cd /etc/mail/auth
Create a new file client-info and below auth in the file.
AuthInfo:gmail.com "U:username" "P:password" "M:PLAIN" AuthInfo: "U:username" "P:Password" "M:PLAIN
makemap -r hash client-info.db < client-info
Add your relay IP
Connect: [your-ip ] RELAY
# Check the /usr/share/doc/sendmail/README.cf file for a description
# of the format of this file. (search for access_db in that file)
# The /usr/share/doc/sendmail/README.cf is part of the sendmail-doc
# package. # If you want to use AuthInfo with "M:PLAIN LOGIN", make sure to have the # cyrus-sasl-plain package installed. # By default we allow relaying from localhost... Connect:localhost.localdomain RELAY Connect:localhost RELAY Connect:127.0.0.1 RELAY
Step 5: Recompiling Sendmail Configuration
Update Sendmail configuration by compiling the /etc/mail/sendmail.mc file using m4 macro processor.
sudo m4 /etc/mail/sendmail.mc > /etc/mail/sendmail.cf
sudo make -C /etc/mail
Once you have recompiled restart the service using below command.
sudo service sendmail restart
Step 6: Send your First Email
sendmail -v firstname.lastname@example.org
You might face this common problem
Disabling HOST statistics file(/var/lib/sendmail/host_status). Creating /etc/mail/sendmail.cf... Creating /etc/mail/submit.cf... Informational: confCR_FILE file empty: /etc/mail/relay-domains Informational: confCT_FILE file empty: /etc/mail/trusted-users Updating /etc/mail/access... Updating /etc/mail/aliases... WARNING: local host name (ixtmixilix) is not qualified; see cf/README: WHO AM I?
This issue occurs when your hostname/domain name is not mapped with your server. It's a warning, that your hostname won’t work outside your local network.
You can simply set your hostname to a registered domain by using below command.
hostnamectl set-hostname my.new-hostname.server
I hope you liked this article where I tried to explain everything in the most layman manner. Using these simple steps you can install Sendmail Server on Centos.
In case of any query, please feel free to comment below.