mail 465邮件配置

本文介绍了如何配置QQ邮箱SMTP服务以实现邮件发送。步骤包括开启SMTP服务并获取授权码,停止并启动postfix服务,创建认证,配置邮件发送者,并通过测试确保设置正确。在生产环境中,可以发送不带或带附件的邮件。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

1.开启QQ邮箱SMTP服务

qq邮箱开启SMTP.jpg

然后点击图片右下角生成授权码 ,获取到授权码

2.停止服务

此操作是在root用户下进行

[root@hadoop000 ~]# service sendmail stop
Redirecting to /bin/systemctl stop  sendmail.service
Failed to stop sendmail.service: Unit sendmail.service not loaded.
[root@hadoop000 ~]# chkconfig sendmail off
服务 sendmail 信息读取出错:没有那个文件或目录

3.启动postfix服务

此操作是在root用户下进行

# 启动postfix
[root@hadoop000 ~]# 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@hadoop000 ~]# 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 hadoop000 systemd[1]: Starting Postfix Mail Transport Agent...
8月 24 16:55:01 hadoop000 aliasesdb[7204]: /usr/sbin/postconf: fatal: parameter i...:1
8月 24 16:55:02 hadoop000 aliasesdb[7204]: newaliases: fatal: parameter inet_inte...:1
8月 24 16:55:02 hadoop000 postfix/sendmail[7206]: fatal: parameter inet_interfaces...1
8月 24 16:55:02 hadoop000 postfix[7210]: fatal: parameter inet_interfaces: no loc...:1
8月 24 16:55:03 hadoop000 systemd[1]: postfix.service: control process exited, co...=1
8月 24 16:55:03 hadoop000 systemd[1]: Failed to start Postfix Mail Transport Agent.
8月 24 16:55:03 hadoop000 systemd[1]: Unit postfix.service entered failed state.
8月 24 16:55:03 hadoop000 systemd[1]: postfix.service failed.
Hint: Some lines were ellipsized, use -l to show in full.

# 检查postfix问题
[root@hadoop000 ~]# postfix check
postfix: fatal: parameter inet_interfaces: no local interface found for ::1

# 需要修改如下配置
[root@hadoop000 ~]# 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@hadoop000 ~]# service postfix start 
# 查看状态
[root@hadoop000 ~]# service postfix status
...
# 显示启动成功
Active: active (running) since 六 2019-08-24 17:02:08 CST; 10s ago
...

# 配置开机自启动
[root@hadoop000 ~]# chkconfig postfix on
注意:正在将请求转发到“systemctl enable postfix.service”。

4.创建认证

此操作是在hadoop用户下

[hadoop@hadoop000 ~]$ mkdir -p ~/.certs/

[hadoop@hadoop000 ~]$ echo -n | openssl s_client -connect smtp.qq.com:465 | sed -ne '/-BEGIN CERTIFICATE-/,/-END CERTIFICATE-/p' > ~/.certs/qq.crt

[hadoop@hadoop000 ~]$ certutil -A -n "GeoTrust SSL CA" -t "C,," -d ~/.certs -i ~/.certs/qq.crt

[hadoop@hadoop000 ~]$ certutil -A -n "GeoTrust Global CA" -t "C,," -d ~/.certs -i ~/.certs/qq.crt certutil -L -d ~/.certs

[hadoop@hadoop000 ~]$ cd ~/.certs

[hadoop@hadoop000 .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@hadoop000 ~]$ 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@hadoop000 ~]$ 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}
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值