天天看点

CentOS 7.4配置mailx基于465端口发送邮件

发送邮件的两种方式:

1、连接现成的smtp服务器去发送(此方法比较简单,直接利用现有的smtp服务器比如qq、新浪、网易等邮箱,只需要直接配置mail.rc文件即可实现)

2、自己搭建私有的smtp服务器(需要用到postfix、bind等服务)

系统环境:CentOS 7.4

邮箱类型:腾讯企业邮箱

1、安装mailx

[root@localhost ~]# yum -y install mailx

2、配置mail.rc文件

PS:首先要保证你的腾讯企业邮箱开启了SMTP服务。

[root@localhost ~]# vim /etc/mail.rc

#配置内容如下(按要求填写哦)

#你的邮箱账号set [email protected]#邮箱所在服务器和端口地址set smtp=smtps://smtp.exmail.qq.com:465#邮箱set [email protected]#密码set smtp-auth-password=xxx#默认login即可set smtp-auth=login#ssl认证方式set ssl-verify=ignore#证书所在目录,这个可以自定义目录所在位置set nss-config-dir=/data/mail/certs

3、配置数字证书

[root@localhost ~]# mkdir -p /data/mail/certs

[root@localhost ~]# cd /data/mail/certs

[root@localhost ~]# echo -n | openssl s_client -connect smtp.exmail.qq.com:465 | sed -ne '/-BEGIN CERTIFICATE-/,/-END CERTIFICATE-/p' > exmail_qq.crt

[root@localhost ~]# certutil -A -n "GeoTrust SSL CA" -t "C,," -d /data/mail/certs/ -i exmail_qq.crt

[root@localhost ~]# certutil -A -n "GeoTrust Global CA" -t "C,," -d /data/mail/certs/ -i exmail_qq.crt

[root@localhost ~]# certutil -A -n "GeoTrust SSL CA - G3" -t "Pu,Pu,Pu" -d . -i exmail_qq.crt

[root@localhost ~]# certutil -L -d /data/mail/certs/

4、发送测试邮件

[root@localhost ~]# echo "邮件测试" |mail -s "测试" 

5、发送文件的另外几种格式

[root@localhost ~]# cat file.txt | mail -s "邮件主题" 

[root@localhost ~]# mail -s "邮件主题"  < file.txt

打开你的163邮箱如果收到此邮箱发来的测试邮件即为配置成功。