This article briefly sorted out the steps of how to install and configure SendMail to send mail on Linux server. This article is not configuring mail server. The specific test environment is CentOS Linux release 7.2.1511 (Core). If there are differences between special platforms, please take the actual situation as the criterion.
Linux System Version View
Check and understand the system version information, mainly if you use rpm installation, you need to download the appropriate version.
[root@mylnx06 ~]# more /etc/redhat-release
CentOS Linux release 7.2.1511 (Core)
Check whether the sendmail component is installed
As shown below, there is no sendmail component installed on the server. Then we can install sendmail components directly using yum.
[root@mylnx06 ~]# rpm -qa | grep sendmail
[root@mylnx06 ~]# yum list sendmail
Loaded plugins: fastestmirror, langpacksLoading mirror speeds from cached hostfile* epel: ftp.cuhk.edu.hkAvailable Packagessendmail.x86_64 8.14.7-4.el7 base
Use yum to install sendmail components. Of course, you can install them in other ways. There is no introduction here.
[root@mylnx06 ~]# yum install sendmail.x86_64
Loaded plugins: fastestmirror, langpacksLoading mirror speeds from cached hostfile* epel: ftp.cuhk.edu.hkResolving Dependencies--> Running transaction check---> Package sendmail.x86_64 0:8.14.7-4.el7 will be installed--> Finished Dependency ResolutionDependencies Resolved========================================================================================================================Package Arch Version Repository Size========================================================================================================================Installing:sendmail x86_64 8.14.7-4.el7 base 722 kTransaction Summary========================================================================================================================Install 1 PackageTotal download size: 722 kInstalled size: 1.6 MIs this ok [y/d/N]: yDownloading packages:sendmail-8.14.7-4.el7.x86_64.rpm | 722 kB 00:00:00Running transaction checkRunning transaction testTransaction test succeededRunning transactionInstalling : sendmail-8.14.7-4.el7.x86_64 1/1Verifying : sendmail-8.14.7-4.el7.x86_64 1/1Installed:sendmail.x86_64 0:8.14.7-4.el7Complete![root@mylnx06 ~]#
Edit / etc/aliases file
Sendmail has a very practical function, which is to alias each account and use a file in / etc/aliases to do user name conversion. So this configuration file is available or not, depending on your needs.
[root@mylnx06 ~]# vi /etc/aliases
#
# Aliases in this file will NOT be expanded in the header from
# Mail, but WILL be visible over networks or from /bin/mail.
#
# >>>>>>>>>> The program "newaliases" must be run after
# >> NOTE >> this file is updated for any changes to
# >>>>>>>>>> show through to sendmail.
#
# Basic system aliases -- these MUST be present.
mailer-daemon: postmasterpostmaster: root# General redirections for pseudo accounts.
bin: rootdaemon: rootadm: rootlp: rootsync: rootshutdown: roothalt: rootmail: rootnews: rootuucp: rootoperator: rootgames: rootgopher: rootftp: rootnobody: rootradiusd: rootnut: rootdbus: rootvcsa: rootcanna: rootwnn: rootrpm: rootnscd: rootpcap: rootapache: rootwebalizer: rootdovecot: rootfax: rootquagga: rootradvd: rootpvm: rootamandabackup: rootprivoxy: rootident: rootnamed: rootxfs: rootgdm: rootmailnull: rootpostgres: rootsshd: rootsmmsp: rootpostfix: rootnetdump: rootldap: rootsquid: rootntp: rootmysql: rootdesktop: rootrpcuser: rootrpc: rootnfsnobody: rootingres: rootsystem: roottoor: rootmanager: rootdumper: rootabuse: rootnewsadm: newsnewsadmin: newsusenet: newsftpadm: ftpftpadmin: ftpftp-adm: ftpftp-admin: ftpwww: webmasterwebmaster: rootnoc: rootsecurity: roothostmaster: rootinfo: postmastermarketing: postmastersales: postmastersupport: postmaster# trap decode to catch security attacks
decode: root# Person who should get root's mail
#root: marc
As shown in the screenshot below, if I configure an alias root, configure to receive mail (the following mail is just a template)
Modify the configuration file sendmail.cf
Modify / etc/mail/sendmail.cf to add the corresponding DS, followed by the IP address of the mail server. Configuration according to the actual situation. In fact, this configuration file, if necessary, there are a lot of need to configure, refinement, here only describes the simplest configuration.
# host/domain names ending with a token in class P are canonical
CP.# "Smart" relay host (may be null)
DS[xxx.xxx.xxx.xxx]# operators that cannot be in local usernames (i.e., network indicators)
CO @ % !# a class with just dot (for identifying canonical names)
Restart sendmail service
[root@mylnx06 ~]# service sendmail status
Redirecting to /bin/systemctl status sendmail.service● sendmail.service - Sendmail Mail Transport AgentLoaded: loaded (/usr/lib/systemd/system/sendmail.service; enabled; vendor preset: disabled)Active: inactive (dead)Feb 22 10:29:45 azlnx06 systemd[1]: Stopped Sendmail Mail Transport Agent.[root@mylnx06 ~]# service sendmail start
Redirecting to /bin/systemctl start sendmail.service[root@mylnx06 ~]# service sendmail status
Redirecting to /bin/systemctl status sendmail.service● sendmail.service - Sendmail Mail Transport AgentLoaded: loaded (/usr/lib/systemd/system/sendmail.service; enabled; vendor preset: disabled)Active: active (running) since Wed 2017-02-22 10:42:02 HKT; 5s agoProcess: 46129 ExecStart=/usr/sbin/sendmail -bd $SENDMAIL_OPTS $SENDMAIL_OPTARG (code=exited, status=0/SUCCESS)Process: 46116 ExecStartPre=/etc/mail/make aliases (code=exited, status=0/SUCCESS)Process: 46115 ExecStartPre=/etc/mail/make (code=exited, status=0/SUCCESS)Main PID: 46131 (sendmail)CGroup: /system.slice/sendmail.service└─46131 sendmail: accepting connectionsFeb 22 10:42:02 azlnx06 systemd[1]: Starting Sendmail Mail Transport Agent...Feb 22 10:42:02 azlnx06 sendmail[46124]: alias database /etc/aliases rebuilt by rootFeb 22 10:42:02 azlnx06 sendmail[46124]: /etc/aliases: 77 aliases, longest 17 bytes, 792 bytes totalFeb 22 10:42:02 azlnx06 sendmail[46131]: starting daemon (8.14.7): SMTP+queueing@01:00:00Feb 22 10:42:02 azlnx06 systemd[1]: PID file /run/sendmail.pid not readable (yet?) after start.Feb 22 10:42:02 azlnx06 systemd[1]: Started Sendmail Mail Transport Agent
Test Mail Service
As shown below, use the mail command to test whether mail is received successfully. If it succeeds, it means that OK was configured before. If no mail was received, the log must be checked and the problem diagnosed according to the specific error information.
[root@mylnx06 ~]# cat > test.txt
it is only test^Z[1]+ Stopped cat > test.txt[root@mylnx06 ~]# mail -s "test" konglb@xxxx.com < test.txt
[root@mylnx06 ~]#
[azrlnx06azlnx06 ~]$ echo 'it is only a test' | mail -s "test eamil" konglb@xxxx.com[azrlnx06@azlnx06 ~]$