一.安装mailx
安装客户端软件
yum -y install mailx
二.修改配置文件
方案一:使用QQ邮箱
vim /etc/mail.rc 在配置文件下方添加如下内容 set bsdcompat set from="xxx@qq.com" set smtp=smtps://smtp.qq.com:465 set smtp-auth-user=xxx@qq.com set smtp-auth-password=QQ邮箱密码 set smtp-auth=login set ssl-verify=ignore set nss-config-dir=/etc/pki/nssdb/
方案二:使用企业邮箱
set bsdcompat set from=企业邮箱账号 set smtp=smtps://smtp.exmail.qq.com:465 set smtp-auth-user=企业邮箱账号 set smtp-auth-password=邮箱密码 set smtp-auth=login set ssl-verify=ignore set nss-config-dir=/etc/pki/nssdb/ 或 set bsdcompat set from="企业邮箱账号" set smtp=smtps://smtp.exmail.qq.com:465 set smtp-auth-user=企业邮箱账号 set smtp-auth-password=邮箱密码 set smtp-auth=login set ssl-verify=ignore set nss-config-dir=/root/.certs
三.开启邮箱的smtp协议
开启腾讯邮箱的smtp发件协议
四.邮箱测试及报错解决
4.1 邮件发送格式
echo "邮件内容" | mail -s "标题" -a 附件文件 收件人邮箱
4.2 证书报错解决
mailx的操作还是蛮简单的,就是一直报一个错误
==Error in certificate: Peer's certificate issuer is not recognized.==
问题原因:证书没有获得认可
解决方法:找个存放证书的目录
1、获取证书
# mkdir -p /root/.certs/ # 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、修改mail.rc配置文件
set nss-config-dir=/root/.certs/
- 3、生效证书
[root@localhost .certs]# pwd
/root/.certs
[root@localhost .certs]# ll
total 80
-rw------- 1 root root 65536 Nov 5 15:33 cert8.db
-rw------- 1 root root 16384 Nov 5 15:33 key3.db
-rw-r--r-- 1 root root 2415 Nov 5 15:29 qq.crt
-rw------- 1 root root 16384 Nov 5 15:29 secmod.db
[root@localhost .certs]# certutil -A -n "GeoTrust SSL CA - G3" -t "Pu,Pu,Pu" -d ./ -i qq.crt
Notice: Trust flag u is set automatically if the private key is present.
4.2 邮箱密码认证错误
- 邮件发送报错:smtp-server: 535 Error: authentication failed
- 报错原因:配置文件中邮箱密码错误
- 解决方法:检查 mail.rc 配置文件中的邮箱密码是否正确
4.3 其它错误
- 邮箱未配置smtp发件协议。
- 邮箱开启了二次验证,建议关闭。
**粗体** _斜体_ [链接](http://example.com) `代码` - 列表 > 引用
。你还可以使用@
来通知其他用户。