一、先去QQ邮箱,开启SMTP和获取授权码
![](https://img.haomeiwen.com/i11706106/21ce7f95e4c1c48c.png)
选择开启SMTP服务
记录你的授权码
![](https://img.haomeiwen.com/i11706106/3332a6c568fe8f0a.png)
二、停止服务
- service sendmail stop
- chkconfig sendmail off
[root@hadoop001 ~]# service sendmail stop
Redirecting to /bin/systemctl stop sendmail.service
Failed to stop sendmail.service: Unit sendmail.service not loaded.
[root@hadoop001 ~]# chkconfig sendmail off
error reading information on service sendmail: No such file or directory
三、.启动postfix服务
- service postfix start
- chkconfig postfix on
- postfix check
- systemctl status postfix
[root@hadoop001 ~]# service postfix start
Redirecting to /bin/systemctl start postfix.service
[root@hadoop001 ~]# chkconfig postfix on
Note: Forwarding request to 'systemctl enable postfix.service'.
[root@hadoop001 ~]# postfix check
[root@hadoop001 ~]# systemctl status postfix
● postfix.service - Postfix Mail Transport Agent
Loaded: loaded (/usr/lib/systemd/system/postfix.service; enabled; vendor preset: disabled)
Active: active (running) since Sat 2019-08-24 14:35:34 CST; 16min ago
Main PID: 1877 (master)
CGroup: /system.slice/postfix.service
├─1877 /usr/libexec/postfix/master -w
├─1878 pickup -l -t unix -u
└─1879 qmgr -l -t unix -u
Aug 24 14:35:31 hadoop001 systemd[1]: Starting Postfix Mail Transport Agent...
Aug 24 14:35:33 hadoop001 postfix/postfix-script[1875]: starting the Postfix mail system
Aug 24 14:35:34 hadoop001 postfix/master[1877]: daemon started -- version 2.10.1, configuration /etc/postfix
Aug 24 14:35:34 hadoop001 systemd[1]: Started Postfix Mail Transport Agent.
四、调整参数:
- vi /etc/postfix/main.cf
- inet_interfaces = all
[root@hadoop001 ~]# vi /etc/postfix/main.cf
inet_interfaces = all
#inet_interfaces = $myhostname
#inet_interfaces = $myhostname, localhost
#inet_interfaces = localhost
五、创建认证
mkdir -p ~/.certs/
echo -n | openssl s_client -connect smtp.qq.com:465 | sed -ne '/-BEGIN CERTIFICATE-/,/-END CERTIFICATE-/p' > ~/.certs/qq.crt
certutil -A -n "GeoTrust SSL CA" -t "C,," -d ~/.certs -i ~/.certs/qq.crt
certutil -A -n "GeoTrust Global CA" -t "C,," -d ~/.certs -i ~/.certs/qq.crt
certutil -L -d ~/.certs
cd ~/.certs
certutil -A -n "GeoTrust SSL CA - G3" -t "Pu,Pu,Pu" -d ./ -i qq.crt
[hadoop@hadoop001 ~]$ mkdir -p ~/.certs/
[hadoop@hadoop001 ~]$ echo -n | openssl s_client -connect smtp.qq.com:465 | sed -ne '/-BEGIN CERTIFICATE-/,/-END CERTIFICATE-/p' > ~/.certs/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 = GeoTrust RSA CA 2018
verify return:1
depth=0 C = CN, ST = Guangdong, L = Shenzhen, O = Tencent Technology (Shenzhen) Company Limited, OU = R&D, CN = pop.qq.com
verify return:1
DONE
[hadoop@hadoop001 ~]$ cd .certs/
[hadoop@hadoop001 .certs]$ ll
total 4
-rw-rw-r-- 1 hadoop hadoop 2529 Aug 24 15:12 qq.crt
[hadoop@hadoop001 .certs]$ certutil -A -n "GeoTrust SSL CA" -t "C,," -d ~/.certs -i ~/.certs/qq.crt
[hadoop@hadoop001 .certs]$ certutil -A -n "GeoTrust Global CA" -t "C,," -d ~/.certs -i ~/.certs/qq.crt
[hadoop@hadoop001 .certs]$ certutil -L -d ~/.certs
Certificate Nickname Trust Attributes
SSL,S/MIME,JAR/XPI
GeoTrust SSL CA C,,
[hadoop@hadoop001 .certs]$ cd ~/.certs
[hadoop@hadoop001 .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.
六、安装mailx
[root@hadoop001 ~]# yum -y install mailx
[root@hadoop001 ~]# which mail
/usr/bin/mail
七、配置邮件发送者
[root@hadoop001 ~]# vi /etc/mail.rc
#qq
set from=xxxxxxxxx@qq.com
set smtp=smtps://smtp.qq.com:465
set smtp-auth-user=xxxxx
#授权码
set smtp-auth-password=xxxxxxxxx
set smtp-auth=login
set ssl-verify=ignore
set nss-config-dir=/home/hadoop/.certs
八、测试
[hadoop@hadoop001 ~]$ echo hello word | mail -s " title" xxxx@qq.com
![](https://img.haomeiwen.com/i11706106/40561e8f6934d46b.png)
如果要实时查看日志
tail -f /var/log/maillog
九、标准
- 发邮件不带附件
EMAILFROM=xxxxxxxx@qq.com
EMAILTO=xxxxxxxx@qq.com
echo -e "`date "+%Y-%m-%d %H:%M:%S"` : The current running $JOB_NAME job num is \
$RUNNINGNUM in 192.168.137.201 ......" | mail \
-r "From: alertAdmin <${EMAILFROM}>" \
-s "Warn: Skip the new $JOB_NAME spark job." ${EMAILTO}
![](https://img.haomeiwen.com/i11706106/a18a75ed811a4aa5.png)
- 发邮件带附件
EMAILFROM=xxxxxxxx@qq.com
EMAILTO=xxxxxxxx@qq.com
echo -e "`date "+%Y-%m-%d %H:%M:%S"` : Please to check the fail sql attachement." \
| mailx \
-r "From: alertAdmin <${EMAILFROM}>" \
-a error.log \
-s "Critical:KSSH fail sql." ${EMAILTO}
网友评论