为避免不必要的麻烦,先卸载其他的邮件服务
yum -y remove postfix
yum -y remove sendmail
一、安装mailx
yum -y install mailx
二、生产一系列证书(配置证书时)
mkdir ~/.certs
#生成证书(执行时mail需要替换为163或者qq)
echo -n | openssl s_client -connect smtp.163.com:465 | sed -ne '/-BEGIN CERTIFICATE-/,/-END CERTIFICATE-/p' > ~/.certs/mail.crt
certutil -A -n "GeoTrust SSL CA" -t "C,," -d ~/.certs -i ~/.certs/mail.crt
certutil -A -n "GeoTrust Global CA" -t "C,," -d ~/.certs -i ~/.certs/mail.crt
certutil -A -n "GeoTrust SSL CA - G3" -t "Pu,Pu,Pu" -d ~/.certs -i ~/.certs/mail.crt
#查看
certutil -L -d /root/.certs
三、配置mail.rc文件
[root@shuai ~]# vim /etc/mail.rc
dG 先删除里面所有的配置信息
163邮箱配置信息:
set from=shuai@163.com
set smtp=smtp.163.com
# set smtp=smtps://smtp.163.com:465 # 配置证书时
set smtp-auth-user=shuai@163.com
set smtp-auth-password=xxxxxxxxxxxxxxxx
set smtp-auth=login
set ssl-verify=ignore
set nss-config-dir=/root/.certs
QQ邮箱配置信息:
set from=1803592721@qq.com
set smtp=smtp.qq.com
# set smtp=smtps://smtp.qq.com:465 # 配置证书时
set smtp-auth-user=1803592721@qq.com
set smtp-auth-password=xxxxxxxxxxxxxxxx
set smtp-auth=login
set ssl-verify=ignore
set nss-config-dir=/root/.certs
四、发送邮件测试
echo "hello" | mail -v -s "the test is mail" ls12345666@qq.com
双引号一定要是英文的
发送成功!
但会提示:
[root@shuai shell]# Error in certificate: Peer's certificate issuer is not recognized.
貌似是无法识别证书的问题,但是不影响邮件的发送,有待解决*
建议优先选择163邮箱使用
mail.rc各配置项的解释:
set from=#邮箱地址
set smtp=#指定第三方发件的smtp服务器地址
set smtp-auth-user=#第三方发邮件的用户名
set smtp-auth-password=#邮箱授权码
set smtp-auth=#SMTP的默认授权方式,默认是login
set ssl-verify=ignore #忽略SSL的检查
set nss-config-dir=/root/.certs #指定证书所在目录
mailx参数说明:
-r 指定发件人
-c 指定抄送人
-b 指定密送人
-s 邮件主题
-V 显示版本
-v 发送过程
多个收件人之间用逗号分隔