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 email@example.com
Common Errors and Exceptions
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
Error 2: Sendmail error 550 5.1.1 “user unknown”
‘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:
- Wrong Recipient address
- The sender would get a bounce message "550 5.1.1 User unknown" if the recipient mailbox is not available.
- This occurs due to human error while subscribing to the mailing list or if you have purchased an email list (this is a bad practice that can result in a downgrade of your IP reputation).
- Recipient mailbox is moved or deleted from the recipient mail server.
- A misconfiguration or bug on the recipient mail server can cause the unavailability of recipient mail account
How to avoid it?
Always validate email id by sending an email confirmation before sending your regular updates.
- DNS setting is incorrect for domain
- 550 error can also occur if MX entry is not resolving correctly or DNS settings are incorrect.
for eg. MX for a domain, xyz.com is resolving some other domains MX.
- In the above case, the recipient account will be unavailable due. so if you are sending an email to firstname.lastname@example.org and it is resolving wrong MX then it will try sending mail to email@example.com
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
- Email filters set for the domain
- These filters are mostly applied to cooperate mailboxes. Also, if the recipient email account has a forwarder set and that is incorrectly set to a nonexisting account it will result in 550 error.
- Filtering for incoming mails using email filters or anti-spam firewalls can end up bouncing emails from certain sender servers.
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.