查看是否已经安装mailx
yum list installed mailx
安装mailx
yum -y install mailx
CentOS默认使用postfix发送邮件
查看postfix是否开启
ps -ef | grep postfix
关闭postfix服务
# 关闭开机自启动
chkconfig postfix off
# 停止服务
service postfix stop
# 关闭sendmail配置
chkconfig sendmail off
# 停止sendmail服务
service sendmail stop
验证postfix服务是否已关闭
ps -ef | grep postfix
配置mailx
vi /etc/mail.rc
添加如下信息:
set from=952051088@qq.com
set smtp=smtps://smtp.qq.com:465
set smtp-auth-user=952051088@qq.com
set smtp-auth-password=授权码(在QQ邮箱处获取)
set smtp-auth=login
set ssl-verify=ignore
# 证书路径
set nss-config-dir=/root/.certs
添加数字证书
创建证书路径
mkdir -p /root/.certs/
创建qq.crt
echo -n | openssl s_client -connect smtp.qq.com:465 | sed -ne '/-BEGIN CERTIFICATE-/,/-END CERTIFICATE-/p' > ~/.certs/qq.crt
设置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
进入/root/.certs/目录
cd /root/.certs/
完整最后的设置
certutil -A -n "GeoTrust SSL CA - G3" -t "Pu,Pu,Pu" -d ~/.certs/./ -i qq.crt
certutil -L -d /root/.certs
发送邮件
echo "邮件正文" | mail -s "邮件主题" 952051088@qq.com
|