ECS通过mail发送邮件

发送邮件报错,因为新购实例默认对外访问25端口封禁状态,建议使用加密465端口

 1、配置mailx

[root@wiki ~]#  yum install -y mailx
##yum安装完mailx之后,/etc下会自动创建一个mail.rc的文件,在最下面追加如下内容即可。
[root@wiki ~]#  vim /etc/mail.rc

##对方收到邮件时显示的发件人
set from=xxxx@163.com

##指定第三方发邮件的smtp服务器地址
set smtp=smtps://smtp.163.com:465

##第三方发邮件的用户名
set smtp-auth-user=xxxx

##邮箱的密码或授权码(163邮箱需要指定授权码)
set smtp-auth-password=xxxx

##SMTP的认证方式,默认是login
set smtp-auth=login

##忽略ssl的检查
set ssl-verify=ignore

##指定证书所在的目录
set nss-config-dir=/home/mail/

##普通服务器配置以下,即可发送邮件了

set from=邮箱账号@163.com smtp=smtp.163.com
set smtp-auth-user=认证用户 smtp-auth-password=163授权码

2、申请证书

##创建目录,用来存放证书
[root@wiki ~]# mkdir -p /home/mail/

##向163申请证书
[root@wiki ~]# echo -n | openssl s_client -connect smtp.163.com:465  | sed -ne '/-BEGIN CERTIFICATE-/,/-END CERTIFICATE-/p' > /home/mail/163.crt
depth=2 C = US, O = GeoTrust Inc., CN = GeoTrust Global CA
verify return:1
depth=1 C = US, O = GeoTrust Inc., CN = GeoTrust SSL CA - G3
verify return:1
depth=0 C = CN, ST = ZheJiang, L = HangZhou, O = "NetEase (Hangzhou) Network Co., Ltd", CN = *.163.com
verify return:1
DONE

##添加一个证书到证书数据库
[root@wiki ~]# certutil -A -n "GeoTrust SSL CA" -t "C,," -d /home/Allen/.certs/163.crt -i /home/mail/163.crt 

##添加一个证书到证书数据库
[root@wiki ~]# certutil -A -n "GeoTrust Global CA" -t "C,," -d /home/Allen/.certs/163.crt -i /home/mail/163.crt 

##列出目录下的证书
[root@wiki ~]# certutil -L -d /home/mail/

Certificate Nickname                                         Trust Attributes
                                                             SSL,S/MIME,JAR/XPI

GeoTrust SSL CA                                              C,,  

[root@wiki ~]# ls /home/Allen/
163.crt    cert8.db   key3.db    secmod.db  

3、标记为信任

[root@wiki ~]# cd /home/mail
[root@wiki ~]# certutil -A -n "GeoTrust SSL CA - G3" -t "Pu,Pu,Pu" -d /home/Allen/ -i 163.crt 
Notice: Trust flag u is set automatically if the private key is present.

#发送测试邮件
[root@wiki ~]# echo "test" | mail -s test xxxx@163.com
原文地址:https://www.cnblogs.com/root0/p/9519490.html