sendmail is a mail system linux system, configure sendmail on the system can use it to send direct mail.
sendmail configuration file
/ etc / mail / the sendmail.cf: Sendmail main configuration file;
/ etc / mail / Access: Access control relay;
/ etc / mail / domainTable; domain mapping;
/ etc / mail / local-host- names; localhost alias;
/ etc / mail / the mailertable: designated special routing rules for a particular domain;
/ etc / mail / virtusertable: virtual domain configuration.
Relay configuration: refers to a server to receive and transfer the source address and destination address are not the mail server of the present.
Set in two files:
/etc/mail/relay-domains
/etc/mail/access。
First, install the software
[root@VM_0_10_centos ~]# yum -y install sendmail sendmail-cf
Start saslauthd service SMTP authentication (default is installed, if not, manually install)
[root@VM_0_10_centos ~]# systemctl restart saslauthd
Second, the mail service configuration
1) Turn off the firewall
[root@VM_0_10_centos ~]# systemctl stopfirewalld [root@VM_0_10_centos ~]# systemctl status firewalld
2) Configuring the SMTP authentication Senmail
the front two rows below dnl contents removed. In sendmail file, dnl comment line represents the act is invalid, so you can open the corresponding settings line by removing the dnl string beginning of the line.
[root@VM_0_10_centos ~]# vim /etc/mail/sendmail.mc TRUST_AUTH_MECH(`EXTERNAL DIGEST-MD5 CRAM-MD5 LOGIN PLAIN')dnl define(`confAUTH_MECHANISMS', `EXTERNAL GSSAPI DIGEST-MD5 CRAM-MD5 LOGIN PLAIN')dnl
3) Set the network access to a Sendmail service (if it is a direct call to the machine, you can not operate, use the default 127.0.0.1. But finally changed to 0.0.0.0)
will be changed to 127.0.0.1 0.0.0.0, which means any the host can access the Sendmail service.
If you only make one network can gain access to Sendmail service, will address 127.0.0.1 changed to a particular segment of the form 192.168.1.0/24.
[root@VM_0_10_centos ~]# vim /etc/mail/sendmail.mc DAEMON_OPTIONS(`Port=smtp,Addr=0.0.0.0, Name=MTA')dnl
4) Generate configuration files
Sendmail configuration file is generated by m4, m4 tool sendmail-cf package. If the system does not recognize the m4 command description sendmail-cf package is not installed
# Before modifying back up [root @ VM_0_10_centos ~] # cp -r the /etc/mail/sendmail.cf /etc/mail/sendmail.cf.bak [root @ VM_0_10_centos ~] # M4 /etc/mail/sendmail.mc> /etc/mail/sendmail.cf
5) to start the service (if you find sendmail Dead But subsys Locked , then the implementation of " Service postfix Status " to see if postfix is enabled by default, if open, then closed postfix, sendmail and then start or restart the service.)
[VM_0_10_centos the root @ ~] # systemctl the restart the sendmail [VM_0_10_centos the root @ ~] # systemctl the restart saslauthd [VM_0_10_centos the root @ ~] # systemctl postfix status (if it is turned on, the status can be changed to stop)
The service is added to boot from Kai
[root@VM_0_10_centos ~]# systemctl enable sendmail.service [root@VM_0_10_centos ~]# systemctl enable saslauthd.service Created symlink from /etc/systemd/system/multi-user.target.wants/saslauthd.service to /usr/lib/systemd/system/saslauthd.se rvice. [root@VM_0_10_centos ~]# systemctl list-unit-files | grep sendmail sendmail.service enabled [root@VM_0_10_centos ~]# systemctl list-unit-files | grep saslauthd saslauthd.service enabled
Third, test sending mail
1) The first method: Install sendmail to use.
# The default seems to have installed [root @ VM_0_10_centos ~] # yum -y install mailx
PS: create a mail file contents, then send an email (note the -s parameter message headers to use single quotes, double quotes can not be used, otherwise the mail will fail!)
[root@VM_0_10_centos ~]# echo 'This is test mail' > /root/testmail.txt [root@VM_0_10_centos ~]# cat /root/testmail.txt This is test mail [root@VM_0_10_centos ~]# mail -s 'Test Mail' [email protected] < /root/testmail.txt
PS: I use here is qq.com, send messages are not received, the authorization code may be needed to open the qq mailbox. Then the job on the server is configured, as follows
First open authorization code:
Slide down, turn on signing two service said it had opened smtp function. Click born into an authorization code follow the prompts to continue can get the authorization code
After sending Click I have been sent, you can generate an authorization code.
Edit the configuration file:
[root @ VM_0_10_centos ~] # vi /etc/mail.rc the SET [email protected] # displayed when you receive a message other senders the SET the SMTP = SMTPS: //smtp.qq.com: 465 # third party smtp mail server address of the SET [email protected] # third-party e-mail user name the SET smtp-auth-password = *********** # authorization code set ssl- = Verify the ignore SET NSS -config-the dir = / the root / .certs / SET SMTP -auth = Login # the SMTP authentication mode
set smtp-use-starttls
Added to the above configuration is saved after restart mail service:
# systemctl restart sendmail # systemctl restart saslauthd
Run the following command to send a test message, if not unexpected, we will soon be able to receive e-mail sent from the server over the test mail.
Here error:
# 创建/root/.certs目录 # mkdir -p /root/.certs [root@VM_0_10_centos .certs]# echo -n | openssl s_client -connect smtp.exmail.qq.com:465 | sed -ne '/-BEGIN CERTIFICATE-/, /-END CERTIFICATE-/p' >qq.crt
depth=2 C = US, O = DigiCert Inc, OU = www.digicert.com, CN = DigiCert Global Root CA verify return:1 depth=1 C = US, O = DigiCert Inc, OU = www.digicert.com, CN = Secure Site CA G2 verify return:1 depth=0 C = CN, ST = Guangdong, L = Shenzhen, O = Tencent Technology (Shenzhen) Company Limited, OU = \E4\BC\81\E4\B8\9A\E 5\BE\AE\E4\BF\A1\E4\BA\A7\E5\93\81\E9\83\A8, CN = *.exmail.qq.comverify return:1 DONE [root@VM_0_10_centos .certs]# certutil -A -n "GeoTrust SSL CA" -t "C,," -d /root/.certs/ -i qq.crt [root@VM_0_10_centos .certs]# certutil -A -n "GeoTrust Global CA" -t "C,," -d /root/.certs/ -i qq.crt [root@VM_0_10_centos .certs]# certutil -L -d /root/.certs/ Certificate Nickname Trust Attributes SSL,S/MIME,JAR/XPI GeoTrust SSL CA C,, [root@VM_0_10_centos .certs]# certutil -A -n "GeoTrust SSL CA - G3" -t "Pu,Pu,Pu" -d ./ -i qq.crt Notice: Trust flag u is set automatically if the private key is present.
This configuration is not resolved, view the log / var / log / mailog (host may be the reason not to resolve)
Solution: Set / etc / hosts to add the following, and then save and exit and restart the service
Well, still not resolved
Reference blog:
https://www.cnblogs.com/kevingrace/p/6143977.html