一、 在QQ邮箱中开启POP


二 、关闭主机的sendmail,开启postfix
(本机若没有两个服务,就需要先安装)本地安装sendmail和postfix
[root@Slave1 ~]#
# yum -y install sendmail
# yum -y install postfix
//sendmail
# service sendmial stop
# chkconfig sendmail off
//postfix
# service postfix start
# chkconfig postfix on
三、创建证书文件
# mkdir -p /root/.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 /root/.certs
# certutil -A -n "GeoTrush SSL CA - G6" -t "Pu,Pu,Pu" -d ./ -i qq.crt
四、在/etc/mail.rc文件末尾添加一下内容
set from=873505960@qq.com
set smtp=smtp.qq.com
set smtp-auth-user=873505960
# 授权码
set smtp-auth-password=yqbuiutisplabcdb
set smtp-auth=login
set smtp-use-starttls
set ssl-verify=ignore
set nss-config-dir=/root/.certs
五、命令行验证邮件服务
# echo Hi~~ | mail -s "ruozebigdata" 873505960@qq.com
//查看邮件日志
# tail -f /var/log/maillog
六、shell脚本发送邮件:
mail_noattachment.sh (不带附件)
#!/bin/bash
JOB_NAME="TEST"
FROM_EMAIL="873505960@qq.com"
TO_EMAIL="873505960@qq.com"
RUNNINGNUM=1
echo -e "`date "+%Y-%m-%d %H:%M:%S"` : The current running $JOB_NAME job num is $RUNNING in 192.168.1.100......" | mail -r "From: alertAdmin <${FROM_EMAIL}>" -s "Warn: Skip the new $JOB_NAME spark job." ${TO_EMAIL}
mail_attachment.sh (带附件)
#!/bin/bash
FROM_EMAIL="873505960@qq.com"
TO_EMAIL="873505960@qq.com"
LOG=/root/shell/ruozebigdata.log
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}

六、 CDH配置邮件,测试(待测试)
- 先单机Edit,输入873505960@qq.com,然后保存重启生效服务配置
- 再单击Send Test Alert
在Liunx中查看邮件日志
$ tail -F /var/log/cloudera-scm-alertpublicsher/mgmt-cmf-mgmt-ALERTPUBLISHER-hadoop35.log.out
注意时区:
- 查看当前时区
命令 : "date -R"- 修改设置Linux服务器时区(Centos7.0)
命令 : "tzselect"- 复制相应的时区文件,替换系统时区文件;
cp /usr/share/zoneinfo/Asia/Shanghai /etc/localtime
发送一个html表格到qq邮箱中:
table.html
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<title>My test page</title>
</head>
<body>
<table border="1">
<tr>
<td>100</td>
<td>200</td>
<td>300</td>
</tr>
<tr>
<td>400</td>
<td>500</td>
<td>600</td>
</tr>
</table>
</body>
</html>
mail_attachment.sh (带附件)
#!/bin/bash
FROM_EMAIL="873505960@qq.com"
TO_EMAIL="873505960@qq.com"
LOG=/root/shell/table.html
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}
$ chmod +x mail_attachment.sh
$ ./mail_attachment.sh