Linux uses mailx to send emails through QQ mailbox account

Step 1: Install mailx

# 安装mailx
yum install -y mailx

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

Step 2: Obtain the authorization code for your email address

  Open the "Settings" - "Account" of the QQ mailbox, as follows: "
Insert image description here
  " Click the "Management Service" here to apply for the authorization code of the mailbox.

Insert image description here

Step 3: Configure mailx service

  Edit the mail configuration file:

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

  Add the following code at the bottom of 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

Step 4: Add digital certificate

  Create a certificate path

mkdir -p /root/.certs/

  Create qq.crt

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

  Set up 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

  Enter the /root/.certs/ directory

cd  /root/.certs/

  ˆContinue setting

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

Step 5: Send a test email!

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

Guess you like

Origin blog.csdn.net/qq_43592352/article/details/133687816