打开QQ邮箱,生成权限码
![](https://img-blog.csdnimg.cn/img_convert/2fb19d2075c95d714e2d16fbad88ed97.png)
![](https://img-blog.csdnimg.cn/img_convert/0404a087b2c5e287570c5f4d7dc6bebe.png)
服务器配置
#下载mailx服务
[root@localhost shell]# yum -y install mailx
#开启postfix功能
[root@localhost shell]# systemctl start postfix
[root@localhost shell]# systemctl status postfix
● postfix.service - Postfix Mail Transport Agent
Loaded: loaded (/usr/lib/systemd/system/postfix.service; disabled; vendor preset: disabled)
Active: active (running) since 五 2020-10-23 01:01:12 CST; 8h ago
.............
#创建证书(直接复制粘贴)
[root@localhost shell]# mkdir -p /root/.certs
[root@localhost shell]# echo -n | openssl s_client -connect smtp.qq.com:465 | sed -ne '/-BEGIN CERTIFICATE-/,/-END CERTIFICATE-/p' > ~/.certs/qq.crt
................
depth=2 C = BE, O = GlobalSign nv-sa, OU = Root CA, CN = GlobalSign Root CA
verify return:1
depth=1 C = BE, O = GlobalSign nv-sa, CN = GlobalSign Organization Validation CA - SHA256 - G2
verify return:1
depth=0 C = CN, ST = guangdong, L = shenzhen, O = Shenzhen Tencent Computer Systems Company Limited, CN = *.mail.qq.com
verify return:1
DONE
..............
[root@localhost .certs]# certutil -A -n "GeoTrust SSL CA" -t "C,," -d ~/.certs -i ~/.certs/qq.crt
[root@localhost .certs]# certutil -A -n "GeoTrust Global CA" -t "C,," -d ~/.certs -i ~/.certs/qq.crt
[root@localhost .certs]# certutil -L -d ~/.certs
.............
Certificate Nickname Trust Attributes
SSL,S/MIME,JAR/XPI
GeoTrust SSL CA C,,
..............
[root@localhost .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.
#修改mail配置文件
[root@localhost .certs]# vim /etc/mail.rc
..........
set from=12xxxxx@qq.com
set smtp=smtp.qq.com
set smtp-auth-user=12xxxx
#授权码
set smtp-auth-password=权限码
set smtp-auth=login
set smtp-use-starttls
set ssl-verify=ignore
set nss-config-dir=/root/.certs
测试
#同步服务器时间,成功5次发送邮件,并附带log附件
[root@localhost shell]# cat ntp.sh
#!/bin/env bash
NTP=ntp1.aliyun.com
dir_log=/opt/ntp.log
count=0
while true
do
ntpdate $NTP >> /opt/ntp.log
if [ $? -ne 0 ];then
echo "同步失败"| mail -s "checkTime" root@localhost
else
count=$[$count+1]
if [ $count -eq 5 ];then
echo "同步5次"| mail -s "checkTime" -a $dir_log 1255109811@qq.com
count=0;
fi
fi
sleep 3
done
![](https://img-blog.csdnimg.cn/img_convert/2b7ac00376977eea3c62648b61974111.png)