①POP3/SMTP服务
QQ邮箱设置内找到POP3/IMAP/SMTP/Exchange/CardDAV/CalDAV服务
开启POP3/SMTP服务,记录授权码
②安装mailx
yum -y install mailx
之前应该移除可能会冲突的postfix和sendmail(我没有尝试是否必须)
yum -y remove postfix
yum -y remove sendmail
③进入/etc/mail.rc 配置邮箱
starttls 方式发送邮件配置
set smtp-use-starttls
set nss-config-dir=/etc/pki/nssdb
set ssl-verify=ignore
set smtp=smtp.qq.com:587
set smtp-auth=login
set smtp-auth-user=xxx@qq.com
set smtp-auth-password=授权码
set from=xxx@qq.com
mail from address must be same as authorization user
④测试
echo "Hello" | mail -v -s "test" xxx@qq.com
⑤待解决
Error in certificate: Peer's certificate issuer is not recognized.
原因:自签名的证书,报错含义是签发证书机构未经认证,无法识别。
方法:(未成功)
mkdir -p /root/.certs/
echo -n | openssl s_client -connect smtp.qq.com:587 | 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
修改 mail.rc 邮件配置,修改 nss-config-dir 为上面命令生成的 /root/.certs,保存
参考:https://www.wpzhiku.com/shi-yong-mailx-tong-guo-smtp-zai-centos-shang-fa-song-you-jian/