mailx配置TSL发送邮件

mailx配置TSL发送邮件

如果是云服务器则需申请解封25端口

进入正题:

一、配置mailx使用SMTP发送邮件:
1、安装mailx;这里直接使用yum install mailx -y 进行安装即可;
2、在/etc/mail.rc配置文件中,在最后面输入以下内容:

1 set from="[email protected]"
2 set smtp=smtp.qq.com
3 set smtp-auth-user=xxx
4 set smtp-auth-password=邮箱授权码    #qq邮箱->设置 -> 账户
5 set smtp-auth=login

配置都很简单,这里就不多说了,有两点需要注意的:

邮箱需要开启SMTP功能,每个邮箱的开启方法都大同小异;
现在大部分邮箱使用SMTP会让你启动一个授权码来代替邮箱密码
具体各个邮箱开启授权码的方式可以直接百度;
二、获取证书

1 mkdir -p /root/.certs/
2 echo -n | openssl s_client -connect smtp.qq.com:465 | sed -ne '/-BEGIN CERTIFICATE-/,/-END CERTIFICATE-/p' > ~/.certs/qq.crt
3 certutil -A -n "GeoTrust SSL CA" -t "C,," -d ~/.certs -i ~/.certs/qq.crt
4 certutil -A -n "GeoTrust Global CA" -t "C,," -d ~/.certs -i ~/.certs/qq.crt
5 certutil -L -d /root/.certs

返回如下提示即可:

  1. **Notice: Trust flag u is set automatically if the private key is present.**

按照上面操作,只要不报错,就是正常的,我们会在/root/.certs下面看到几个证书文件,说明操作成功了;至于为什么

要这么做,不要问我,我也是COPY大神的办法;

证书配置好了,下面我们就要来配置mail.rc配置文件了,和最开始的不同,这里我们就需要配置和TSL相关的东西了

set from=[email protected]
set smtp=smtps://smtp.qq.com:465
set smtp-auth-user=[email protected]
set smtp-auth-password=你的授权码
set smtp-auth=login
set smtp-use-starttls 
set ssl-verify=ignore
set nss-config-dir=/root/.certs

至此,已经完成了 mailx 结合 QQ 邮箱发送系统邮件的部署了,通过命令行发送测试邮件试试吧:

1 echo "测试邮件" | mail -s "测试"  [email protected]

 三 发送邮件

1 echo "这里输入你邮件内容" | mailx -s "邮件标题" -a file.txt  [email protected]
2 mail -s "邮件标题" -a file.txt [email protected]  <  message.txt
3 -s  标题
4 -a  附件

 

猜你喜欢

转载自www.cnblogs.com/doufy/p/11014778.html