Linux通过QQ邮箱账号使用mailx发送邮件

第一步:安装mailx

# 安装mailx
yum install -y mailx

# 检查是否已安装相关依赖
rpm -qa | grep mail

第二步:获取邮箱的授权码

  打开QQ邮箱的“设置”——“账号”,如下:
在这里插入图片描述
  点击此处的“管理服务”,即可申请邮箱的授权码。

在这里插入图片描述

第三步:配置mailx服务

  编辑mail的配置文件:

# 配置,QQ邮箱为例
vi /etc/mail.rc

  在mail.rc最下方添加如下代码:

set from=your_account@qq.com # 邮箱地址
set smtp=smtps://smtp.qq.com:465
set smtp-auth-user=your_account@qq.com # 邮箱地址 同上
set smtp-auth-password=your_code # 邮箱的授权码
set smtp-auth=login
set ssl-verify=ignore
set nss-config-dir=/root/.certs

第四步:添加数字证书

  创建证书路径

mkdir -p /root/.certs/

  创建qq.crt

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

  设置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

  进入/root/.certs/目录

cd  /root/.certs/

  继续设置

certutil -A -n "GeoTrust SSL CA - G3" -t "Pu,Pu,Pu" -d ~/.certs/./ -i qq.crt
certutil -L -d /root/.certs

第五步:发送邮件测试!

# -a指定附件,可同时发送给多个邮箱
echo "邮件正文" | mailx -v -s "邮件主题" -a /root/install.log -a  /root/install2.log xxoo@qq.com,ooxx@163.com

猜你喜欢

转载自blog.csdn.net/qq_43592352/article/details/133687816