mail 465邮件配置
2019-08-24 本文已影响0人
cllblogs
1.开启QQ邮箱SMTP服务
qq邮箱开启SMTP.jpg然后点击图片右下角生成授权码 ,获取到授权码
2.停止服务
此操作是在root用户下进行
[root@ruozedata001 ~]# service sendmail stop
Redirecting to /bin/systemctl stop sendmail.service
Failed to stop sendmail.service: Unit sendmail.service not loaded.
[root@ruozedata001 ~]# chkconfig sendmail off
服务 sendmail 信息读取出错:没有那个文件或目录
3.启动postfix服务
此操作是在root用户下进行
# 启动postfix
[root@ruozedata001 ~]# service postfix start
Redirecting to /bin/systemctl start postfix.service
Job for postfix.service failed because the control process exited with error code. See "systemctl status postfix.service" and "journalctl -xe" for details.
# 查看postfix状态
[root@ruozedata001 ~]# service postfix status
Redirecting to /bin/systemctl status postfix.service
● postfix.service - Postfix Mail Transport Agent
Loaded: loaded (/usr/lib/systemd/system/postfix.service; enabled; vendor preset: disabled)
# 这行表示启动失败了
Active: failed (Result: exit-code) since 六 2019-08-24 16:55:03 CST; 1min 34s ago
8月 24 16:55:01 ruozedata001 systemd[1]: Starting Postfix Mail Transport Agent...
8月 24 16:55:01 ruozedata001 aliasesdb[7204]: /usr/sbin/postconf: fatal: parameter i...:1
8月 24 16:55:02 ruozedata001 aliasesdb[7204]: newaliases: fatal: parameter inet_inte...:1
8月 24 16:55:02 ruozedata001 postfix/sendmail[7206]: fatal: parameter inet_interfaces...1
8月 24 16:55:02 ruozedata001 postfix[7210]: fatal: parameter inet_interfaces: no loc...:1
8月 24 16:55:03 ruozedata001 systemd[1]: postfix.service: control process exited, co...=1
8月 24 16:55:03 ruozedata001 systemd[1]: Failed to start Postfix Mail Transport Agent.
8月 24 16:55:03 ruozedata001 systemd[1]: Unit postfix.service entered failed state.
8月 24 16:55:03 ruozedata001 systemd[1]: postfix.service failed.
Hint: Some lines were ellipsized, use -l to show in full.
# 检查postfix问题
[root@ruozedata001 ~]# postfix check
postfix: fatal: parameter inet_interfaces: no local interface found for ::1
# 需要修改如下配置
[root@ruozedata001 ~]# vi /etc/postfix/main.cf
...
#inet_interfaces = $myhostname, localhost
#inet_interfaces = localhost
# 修改为
inet_interfaces = all
# Enable IPv4, and IPv6 if supported
inet_protocols = all
...
# 重新启动下postfix
[root@ruozedata001 ~]# service postfix start
# 查看状态
[root@ruozedata001 ~]# service postfix status
...
# 显示启动成功
Active: active (running) since 六 2019-08-24 17:02:08 CST; 10s ago
...
# 配置开机自启动
[root@ruozedata001 ~]# chkconfig postfix on
注意:正在将请求转发到“systemctl enable postfix.service”。
4.创建认证
此操作是在hadoop用户下
[hadoop@ruozedata001 ~]$ mkdir -p ~/.certs/
[hadoop@ruozedata001 ~]$ echo -n | openssl s_client -connect smtp.qq.com:465 | sed -ne '/-BEGIN CERTIFICATE-/,/-END CERTIFICATE-/p' > ~/.certs/qq.crt
[hadoop@ruozedata001 ~]$ certutil -A -n "GeoTrust SSL CA" -t "C,," -d ~/.certs -i ~/.certs/qq.crt
[hadoop@ruozedata001 ~]$ certutil -A -n "GeoTrust Global CA" -t "C,," -d ~/.certs -i ~/.certs/qq.crt certutil -L -d ~/.certs
[hadoop@ruozedata001 ~]$ cd ~/.certs
[hadoop@ruozedata001 .certs]$ certutil -A -n "GeoTrust SSL CA - G3" -t "Pu,Pu,Pu" -d ./ -i qq.crt
# 出现这句话 表示配置成功了
Notice: Trust flag u is set automatically if the private key is present.
5.配置邮件发送者
此操作是在root用户下操作
[root@ruozedata001 ~]$ vi /etc/mail.rc
set from=503757851@qq.com
set smtp=smtps://smtp.qq.com:465
set smtp-auth-user=503757851
#授权码
set smtp-auth-password=xxxxxxxxxx
set smtp-auth=login
set ssl-verify=ignore
set nss-config-dir=/home/hadoop/.certs
6.测试
[hadoop@ruozedata001 ~]$ echo hello word | mail -s " title" 503757851@qq.com
QQ邮箱收到邮件 即表示成功
7.生产使用
- 发邮件不不带附件
EMAILFROM=503757851@qq.com
EMAILTO=503757851@qq.com # 多个接受者用 , 分割
echo -e "`date "+%Y-%m-%d %H:%M:%S"` : The current running $JOB_NAME job num is $RUNNINGNUM in 192.168.137.201 ......" | mail \
-r "From: alertAdmin <${EMAILFROM}>" \
-s "Warn: Skip the new $JOB_NAME spark job." ${EMAILTO}
- 发邮件带附件
echo -e "`date "+%Y-%m-%d %H:%M:%S"` : Please to check the fail sql attachement."|mailx \
-r "From: alertAdmin <${EMAILFROM}>" \
-a error.log \
-s "Critical:KSSH fail sql." ${EMAILTO}