使用阿里云服务器shell脚本发送邮件

1.开放端口

阿里云服务器ESC安全组开放25、465端口
在这里插入图片描述

2.获取邮箱授权码

本文使用的139邮箱,其他QQ、163邮箱其实类似
在这里插入图片描述

3.创建认证

下面操作可以直接复制

mkdir /root/.certs/  #需要先创建文件夹
####139证书创建
echo -n | openssl s_client -connect smtp.139.com:465 | sed -ne '/-BEGIN CERTIFICATE-/,/-END CERTIFICATE-/p' > ~/.certs/139.crt
certutil -A -n "GeoTrust SSL CA" -t "C,," -d ~/.certs -i ~/.certs/139.crt
certutil -A -n "GeoTrust Global CA" -t "C,," -d ~/.certs -i ~/.certs/139.crt
certutil -L -d /root/.certs
cd /root/.certs
certutil -A -n "GeoTrust SSL CA - G3" -t "Pu,Pu,Pu" -d ./ -i 139.crt
####阿里云证书创建
echo -n | openssl s_client -connect smtp.qiye.aliyun.com:465 | sed -ne '/-BEGIN CERTIFICATE-/,/-END CERTIFICATE-/p' > ~/.certs/qiye.aliyun.com.crt
certutil -A -n "GeoTrust SSL CA" -t "C,," -d ~/.certs -i ~/.certs/qiye.aliyun.com.crt
certutil -A -n "GeoTrust Global CA" -t "C,," -d ~/.certs -i ~/.certs/qiye.aliyun.com.crt

在这里插入图片描述
显示:Notice: Trust flag u is set automatically if the private key is present.为正常
在这里插入图片描述

4.安装mailx并配置

yum -y install mailx
vi /etc/mail.rc

set from=******@139.com  #你的发件邮箱
set smtp=smtps://smtp.139.com    #139邮箱就写这个,网易邮箱写smtp.163.com,qq邮箱写smtp.qq.com,一定要加上smtps://
set smtp-auth-user=******@139.com  #发件人
set smtp-auth-password=0e6**************  #邮箱授权码
set smtp-auth=login
set ssl-verify=ignore
set nss-config-dir=/root/.certs

测试:
echo “send a test mail” | mail -s “test2024” ******@139.com

问题记录:

  1. 所有配置都正确了,为什么还是不行!提示:
SSL/TLS handshake failed: SSL received a malformed Alert record.
"/root/dead.letter" 11/306
. . . message not sent.

答:请在mail.rc 中,将第四步中的命令set smtp-use-starttls去掉
2.报错如下:
could not connect: Connection timed out
“/root/dead.letter” 11/299
. . . message not sent.
将/etc/mail.rc中的set smtp=smtp.139.com改为set smtp=smtps://smtp.139.com

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值