先设置QQ邮箱授权码
打开SMTP服务发送短信会得到短信验证码(后面配置环境会用到)
先确认Centos是否打开postfix邮件服务
systemctl status postfix
若显示如下 证明邮件服务正在运行
确认服务器是否安装mailx
which mailx
(若没安装,利用yum -y install mailx进行安装)
使用SMTP非加密端口发送邮件
(1)利用vi /etc/mail.rc 配置文件,增加以下内容
set from=******@qq.com #显示的发件人,必须和认证用户邮箱一致
set smtp=smtp.qq.com #指定第三方发邮件的smtp服务器地址
set smtp-auth-user=******@qq.com #SMTP认证用户邮箱
set smtp-auth-password=xxxxxxx'x'x #SMTP授权码,不是邮箱密码
set smtp-auth=login #SMTP认证方式,默认是login,也可以改成CRAM-MD5或PLAIN方式
(2)使用SSL加密的方式,需要 QQ 邮箱的 SSL 证书,所以还需要手动的获取QQ邮箱的证书。具体命令如下:
#创建一个存放证书的目录
mkdir -p /root/.certs/
#获取QQ 邮箱的 SSL 证书
echo -n | openssl s_client -connect smtp.qq.com:465 | 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
使用上面的配置,邮件是完全能够发出去的,但是发送邮件的时候会提示 “Error in certificate: Peer’s certificate issuer is not recognized.”提示,运行以下命令即可。
cd /root/.certs/
ll
certutil -A -n "GeoTrust SSL CA - G3" -t "Pu,Pu,Pu" -d ./ -i qq.crt
(3)进行测试
利用下面命令echo 'This is a test. - - From Postfix' | mail -s 'Test Postfix' -r ******@qq.com
以上就是Linux中如何给QQ邮箱发送邮件的方法以及步骤。
感谢阅读,一起进步,一键三连,谢谢大家!