2.mail 465邮件发送案例(含有不带附件和带附件log文件发送)
1. 打开 465端口
2. 进入QQ 邮箱进行设置
设置 --> 账户 -->
开启POP3/SMTP 服务, 此时会提示发送短信
发送之后, 点击"我已发送" 获得授权码
3. 关闭 sendmail 服务
4. 启动 postfix
提示失败
失败原因是 接口只设置为本地了, 需要设置为 all
vi /etc/postfix/main.cf
再次启动, 成功
5. 创建认证
mkdir -p /home/hadoop/.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 /home/hadoop/.certs
cd /home/hadoop/.certs
certutil -A -n "GeoTrust SSL CA - G3" -t "Pu,Pu,Pu" -d ./ -i qq.crt
6. 配置邮件发送者
vi /etc/mail.rc (使用root用户编辑)
set smtp=smtps://smtp.qq.com:465
set smtp-auth-user=595113265
#授权码
set smtp-auth-password=xxx
set smtp-auth=login
set ssl-verify=ignore
set nss-config-dir=/home/hadoop/.certs
7. 测试
echo hello word | mail -s " title" [email protected]
发送成功
8. 不带附件和带附件邮件发送
1) 不带附件
echo -e "`date "+%Y-%m-%d %H:%M:%S"` : The current running $JOB_NAME job num is
$RUNNINGNUM in `ifconfig |grep broadcast | awk -F ' ' '{print $2}'` ......" | mail \
-r "From: alertAdmin <${EMAIL}>" \
-s "Warn: Skip the new $JOB_NAME spark job." ${EMAIL}
执行成功
2) 带附件
这里使用 的是 mailx 发送
编辑一个 error.log 文件
echo "this is test send mail with attachment" >> error.log
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}
发送成功