The author voluntarily contributed this tutorial as a part of Pepipost Write to Contribute program.
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.
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 Downloading packages: (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 Running transaction 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 Installed: 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 Complete!
OR
rpm -qa | grep sendmail
Before directly edit /etc/mail/sendmail.mc for configuration we need to understand important file existence in /etc/mail directory.
Make the following changes in sendmail.mc file below is the command:
vim /etc/mail/sendmail.mc
define(`SMART_HOST', `smtp.gmail.com')dnl
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
MASQUERADE_AS(`mydomain.com')dnl
Save and exit the file.
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.
vim client-info 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
vi /etc/mail/access
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
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
OR
sudo make -C /etc/mail
Once you have recompiled restart the service using below command.
sudo service sendmail restart
sendmail -v myemailid@gmail.com
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
‘550 5.1.1 User unknown’ is the most common issue which occurs while sending mails to Exchange/Recipient servers. 550 error means there is a problem with the recipient server due to which such emails are not delivered. Such issues arise not only with the Sendmail server but with postfix, Exim, etc.
Possible reasons for the occurrence of this issue:
1. Wrong Recipient address
How to avoid it?
Always validate email id by sending an email confirmation before sending your regular updates.
2. DNS setting is incorrect for domain
How to avoid it?
Check your MX record by using dig from the command line:
dig example.com MX
Note: If dig is not installed try using;
sudo apt-get install dig -y sudo yum install dig -y sudo dnf install dig -y
3. Email filters set for the domain
How to avoid?
Check your outgoing firewalls and rules, if any. If all good, contact recipient server support and get the email filters verified for any erroneous filters or rules that can be blocking mails.
Hope you liked this article, where the A-Z of Sendmail is explained in simple language. Using these simple steps you can install Sendmail Server on Centos.
In case you are facing some issues which are not listed above in the tutorial, or you have some suggestions, then please feel free to contribute below in comments.