文章目录
1. 生成QQ邮箱登录授权码
开启SMTP服务,获取授权码
2. 邮件服务器配置
2.1 关闭sendmail服务
#我这里没有sendmail服务
[root@hadoop614~]# service sendmail status
sendmail: unrecognized service
[root@hadoop614~]# service sendmail stop
sendmail: unrecognized service
2.2 开启postfix服务
[root@hadoop614~]# service postfix status
master is stopped
[root@hadoop614~]# service postfix start
Starting postfix: [ OK ]
[root@hadoop614 ~]# service postfix status
master (pid 2566)) is running...
2.3 创建证书
[root@hadoop614 ~]# mkdir .certs
[root@hadoop614 ~]# cd .certs/
[root@hadoop614 .certs]# echo -n | openssl s_client -connect smtp.qq.com:465 | sed -ne '/-BEGIN CERTIFICATE-/,/-END CERTIFICATE-/p' > ~/.certs/qq.crt
[root@hadoop614 .certs]# certutil -A -n "GeoTrust SSL CA" -t "C,," -d ~/.certs -i ~/.certs/qq.crt
[root@hadoop614 .certs]# certutil -A -n "GeoTrust Global CA" -t "C,," -d ~/.certs -i ~/.certs/qq.crt
[root@hadoop614 .certs]# certutil -L -d /root/.cert
[root@hadoop614 .certs]# certutil -A -n "GeoTrust SSL CA - G3" -t "Pu,Pu,Pu" -d ./ -i qq.crt
2.4 配置mail.rc配置文件
在最后追加一下内容
set from=你的QQ邮箱
set smtp=smtp.qq.com
set smtp-auth-user=你的QQ号
#授权码
set smtp-auth-password=你的授权码
set smtp-auth=login
set smtp-use-starttls
set ssl-verify=ignore
set nss-config-dir=/root/.certs
2.5 测试
想自己邮箱发送一条测试邮件
[root@hadoop614 .certs]# echo hello word | mail -s " title" xxxx@qq.com
3 发送一个带附件的邮件
[root@hadoop614 shell]# vi mail_attachment.sh
#!/bin/bash
FROM_EMAIL="1620421126@qq.com"
TO_EMAIL="1620421126@qq.com"
LOG=/root/shell/sh.help
echo -e "`date "+%Y-%m-%d %H:%M:%S"` : Please to check the fail sql attachement." | mailx \
-r "From: alertAdmin <${FROM_EMAIL}>" \
-a ${LOG} \
-s "Critical:DSHS fail sql." ${TO_EMAIL}