1.配置163授权
2.配置mail
vim /etc/mail.rc
添加以下内容
set from=xxx@163.com #发件人,把自己的163邮箱账号地址写上去
set smtp=smtps://smtp.163.com:465 #这个配置不用变
set smtp-auth-user=xxx@163.com #这个是邮箱登录用户,写成自己的邮箱账号
set smtp-auth-password=xxx #授权码(把第一步的授权码拿过来)
set smtp-auth=login #默认login
set nss-config-dir=/root/.certs #证书存放位置
set ssl-verify=ignore
3.生成密钥
[root@aaa~] mkdir -p /root/.certs/
[root@aaa~] echo -n | openssl s_client -connect smtp.163.com:465 | sed -ne '/-BEGIN CERTIFICATE-/,/-END CERTIFICATE-/p' > ~/.certs/163.crt
[root@aaa~] certutil -A -n "GeoTrust SSL CA" -t "C,," -d ~/.certs -i ~/.certs/163.crt
[root@aaa~] certutil -A -n "GeoTrust Global CA" -t "C,," -d ~/.certs -i ~/.certs/163.crt
[root@aaa~] certutil -A -n "GeoTrust SSL CA - G3" -t "Pu,Pu,Pu" -d ~/.certs/./ -i 163.crt
[root@aaa~] certutil -L -d /root/.certs
4.测试使用
echo "test"| mail -s "测试" 邮箱地址
echo "巡检结果" | mail -s "阿里云服务器" -a /root/utils/log/HostDailyCheck-iZbp177qmn3ey757jvbzayZ-20210117.txt 邮箱地址
-s参数是主题名称
-a参数是作为附件发送到邮箱里面
测试时可能会遇到问题,像下面图中报错
可以参考链接,去看下
http://help.163.com/09/1224/17/5RAJ4LMH00753VB8.html