使用465端口发送邮件

一、问题描述

最近由于业务需求,定位到服务发送邮件环节故障,服务器拒绝了25端口,改为mailx工具来进行邮件发送服务。

 

二、使用465端口加密发送邮件

1 关闭其它的邮件工具

[root@test01 ~]# systemctl stop sendmail
[root@test01 ~]# systemctl stop postfix

 

2 安装mailx

[root@test01 ~]# yum -y install mailx

3 开启smtp

在任何邮箱平台中开启smtp,开启后会得到一个授权码,这个授权码就代替了密码(自行去邮箱开启)。我使用的是sina邮箱

4 请求数字证书

(这里用的sina邮箱,所以向sina请求证书)

[root@test01 ~]# mkdir .certs

[root@test01 ~]# echo -n | openssl s_client -connect smtp.sina.com:465 | sed -ne '/-BEGIN CERTIFICATE-/,/-END CERTIFICATE-/p' > /root/.certs/sina.crt

[root@test01 ~]# certutil -A -n "GeoTrust SSL CA" -t "C,," -d /root/.certs -i /root/.certs/sina.crt

[root@test01 ~]# certutil -A -n "GeoTrust Global CA" -t "C,," -d /root/.certs -i /root/.certs/sina.crt

[root@test01 ~]# certutil -A -n "GeoTrust SSL CA - G3" -t "Pu,Pu,Pu" -d /root/.certs/./ -i /root/.certs/sina.crt

Notice: Trust flag u is set automatically if the private key is present.

[root@test01 ~]# ls /root/.certs/

sina.crt cert8.db key3.db secmod.db

[root@test01 ~]# certutil -L -d /root/.certs

Certificate Nickname Trust Attributes

SSL,S/MIME,JAR/XPI

 
GeoTrust SSL CA P,P,P

 

5 配置/etc/mail.rc

[root@test01 ~]# vim /etc/mail.rc

set from=xxx@sina.com #之前设置好的邮箱地址
set smtp="smtps://smtp.sina.com:465" #邮件服务器
set smtp-auth-user=xxx@sina.com #之前设置好的邮箱地址
set smtp-auth-password=xxxx #授权码
set smtp-auth=login #默认login即可
set ssl-verify=ignore #ssl认证方式
set nss-config-dir=/root/.certs #证书所在目录

6 发送邮件测试

[root@test01 /opt]# mail -s "test" xxx@sina.com

  hello world
  EOT

邮件发送成功

 

posted @ 2021-08-03 17:10  alisapine  阅读(1384)  评论(0编辑  收藏  举报