- 以下以qq邮箱为例
一、准备工作
1、邮箱服务
- 登录QQ邮箱,开启SMTP服务并获取授权码:
- 设置 --> 账户
- 设置 --> 账户
2、停止服务
service sendmail stopchkconfig sendmail off
3、启动postfix服务
service postfix startchkconfig postfix onpostfix checksystemctl status postfix
4、安装mail命令
yum -y install mailx
5、调整参数
vi /etc/postfix/main.cfinet_interfaces = all
6、创建认证
mkdir -p /.certs/echo -n | openssl s_client -connect smtp.qq.com:465 | sed -ne '/-BEGIN CERTIFICATE-/,/-END CERTIFICATE-/p' > /.certs/qq.crtcertutil -A -n "GeoTrust SSL CA" -t "C,," -d /.certs -i /.certs/qq.crtcertutil -A -n "GeoTrust Global CA" -t "C,," -d ~/.certs -i /.certs/qq.crtcertutil -L -d /.certscd /.certscertutil -A -n "GeoTrust SSL CA - G3" -t "Pu,Pu,Pu" -d ./ -i qq.crt
7、配置邮件发送者
vi /etc/mail.rc-
# 邮箱号 set from=XXXXXXXXXX@qq.com set smtp=smtps://smtp.qq.com:465 set smtp-auth-user=XXXXXXXXXX # 授权码 set smtp-auth-password=YYYYYYYYYYY set smtp-auth=login set ssl-verify=ignore set nss-config-dir=/.certs
-
二、测试
echo hello word | mail -s " title" XXXXXXXXXX@qq.com- 实时查看日志:
tail -f /var/log/maillog
三、相关标准示例
发邮件不带附件
-
EMAIL=XXXXXXXXXX@qq.com echo -e "`date "+%Y-%m-%d %H:%M:%S"` : The current running $JOB_NAME job num is $RUNNINGNUM in 主机名 ......" | mail \ -r "From: alertAdmin <${EMAIL}>" \ -s "Warn: Skip the new $JOB_NAME spark job." ${EMAIL}
发邮件带附件
-
echo -e "`date "+%Y-%m-%d %H:%M:%S"` : Please to check the fail sql attachement." | mailx \ -r "From: alertAdmin <${EMAIL}>" \ -a error.log \ -s "Critical:KSSH fail sql." ${EMAIL}