方式一:默认使用25端口
# yum install sendmail -y
# yum install mailx -y
# vim /etc/mail.rc
末尾添加
set from=xxxx@xxx
set smtp=smtp.mxhichina.com
set smtp-auth-user=xxxx@xxx
set smtp-auth-password=xxx
set smtp-auth=login
set ssl-verify=ignore
# service sendmail start
测试
# echo "ricoh web error" | mail -s "web error" "xxxx@qq.com"
方式二:使用465端口和证书
# yum install sendmail -y
# yum install mailx -y
# vim /etc/mail.rc
末尾添加
#默认25端口不可用即使服务器开启也不可用,需要使用465端口 同时需要生成证书
set from=servergz@yeah.net
set smtp=smtps://smtp.yeah.net:465
set smtp-auth-user=servergz@yeah.net
set smtp-auth-password=VATYGRCTPLBVPUKH
set smtp-auth=login
set ssl-verify=ignore
set nss-config-dir=/root/.certs
生成证书:
# mkdir -p /root/.certs/
# echo -n | openssl s_client -connect smtp.mxhichina.com:465 | sed -ne '/-BEGIN CERTIFICATE-/,/-END CERTIFICATE-/p' > ~/.certs/mxhi.crt
# certutil -A -n "GeoTrust SSL CA" -t "C,," -d ~/.certs -i ~/.certs/mxhi.crt
---如果报 -bash: certutil: command not found
# yum install nss-tools -y
重新执行
# certutil -A -n "GeoTrust Global CA" -t "C,," -d ~/.certs -i ~/.certs/mxhi.crt
# certutil -L -d /root/.certs
# cd /root/.certs
# certutil -A -n "GeoTrust SSL CA - G3" -t "Pu,Pu,Pu" -d ./ -i mxhi.crt
# service sendmail start
测试
# echo "this is content1" | mail -s "this is title1" "zhumin@jorudan.com.cn"