Linux下使用QQ邮箱发送邮件

目的:使用QQ邮箱SMTP发信服务器发送电子邮件

实验一、使用SMTP非加密端口发送邮件

(1)编辑/etc/mail.rc 配置文件,增加以下内容

set [email protected]   #显示的发件人,必须和认证用户邮箱一致
set smtp=smtp.qq.com        #指定第三方发邮件的smtp服务器地址
set [email protected]    #SMTP认证用户邮箱
set smtp-auth-password=xxxxxxx'x'x     #SMTP授权码,不是邮箱密码
set smtp-auth=login   # 认证方式,默认是login,也可以改成CRAM-MD5或PLAIN方式

可以使用mail,mailx,mutt测试

实验二、使用SSL SMTP发送邮件

(1)使用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

(2)为了避免出现提示“Error in certificate: Peer's certificate issuer is not recognized.”执行下面的命令

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

(3)编辑/etc/mail.rc配置文件,增加配置

set smtp=smtps://smtp.qq.com:465
# set smtp-use-starttls
set ssl-verify=ignore
set nss-config-dir=/root/.certs
发布了22 篇原创文章 · 获赞 4 · 访问量 4844

猜你喜欢

转载自blog.csdn.net/guo1wu3shi4/article/details/92849519