CentOS配置mail.rc通过465端口发送邮件(centos转发端口)
admin2024-08-14 10:14:38Linux运维
需要先启动postfix服务
CentOS 7 启动:systemctl start postfix
#1、创建目录,用来存放证书
[root@shnne ~]# mkdir -p /root/.certs/
#2、向126请求证书
[root@shnne ~]# echo -n | openssl s_client -connect smtp.126.com:465 | sed -ne '/-BEGIN CERTIFICATE-/,/-END CERTIFICATE-/p' > ~/.certs/126.crt
depth=2 C = US, O = DigiCert Inc, OU = www.digicert.com, CN = DigiCert Global Root CA
verify return:1
depth=1 C = US, O = DigiCert Inc, OU = www.digicert.com, CN = GeoTrust CN RSA CA G1
verify return:1
depth=0 C = CN, ST = Zhejiang, L = Hangzhou, O = "NetEase (Hangzhou) Network Co., Ltd", OU = IT Dept., CN = *.126.com
verify return:1
DONE
#3、添加一个证书到证书数据库中
[root@shnne ~]# certutil -A -n "GeoTrust SSL CA" -t "C,," -d ~/.certs -i ~/.certs/126.crt
#4、添加一个证书到证书数据库中
[root@shnne ~]# certutil -A -n "GeoTrust Global CA" -t "C,," -d ~/.certs -i ~/.certs/126.crt
#5、列出目录下证书
[root@shnne ~]# certutil -L -d /root/.certs
Certificate Nickname Trust Attributes
SSL,S/MIME,JAR/XPI
GeoTrust SSL CA C,,
#6、然后前往126邮箱打开smtp并获取客户端授权码
网页正上方:设置→POP3/SMTP/IMAP
网页左侧:客户端授权密码
#7、最后配置/etc/mail.rc,结尾添加如下内容:
set smtp=smtps://smtp.126.com:465
set smtp-auth=login
set smtp-auth-user=shnne
set smtp-auth-password=password客户端授权密码
set ssl-verify=ignore
set nss-config-dir=/root/.certs
#set nss-config-dir=/etc/pki/nssdb (如果没有上面这条,就用此条)
set from=shnne@126.com
#7、现在发送测试邮件
看起来已经成功了,但是发送完邮件还有报错:证书不被信任,且命令行就此卡住,直接敲回车重新进入命令提示符
[root@shnne ~]# echo "content test mail" | mail -s "subject test" postmaster@shnne.com
[root@shnne ~]# Error in certificate: Peer's certificate issuer is not recognized.
[root@shnne ~]# cd /root/.certs/
[root@shnne .certs]# ll
total 80
-rw-r--r-- 1 root root 2419 Jan 20 15:48 126.crt
-rw------- 1 root root 65536 Jan 20 15:50 cert8.db
-rw------- 1 root root 16384 Jan 20 15:50 key3.db
-rw------- 1 root root 16384 Jan 20 15:49 secmod.db
[root@shnne .certs]# certutil -A -n "GeoTrust SSL CA - G3" -t "Pu,Pu,Pu" -d ./ -i 126.crt
Notice: Trust flag u is set automatically if the private key is present.
再次测试问题解决