云服务器如何发送邮件

在共有云上目前都是封锁25端口的,也就是说想要在服务器上搭建SMTP是不可能的,除非申请解封25端口。
但是一般情况为了方便使用,可以直接选择第三方的SMTP服务器,如163,qq等等,省去自建的麻烦。

操作如下:

  1. 进入云服务器,检测是否安装mailx,如果没有则自行安装。
[root@VM-0-2-centos .certs]# rpm -qa | grep mailx
libreport-plugin-mailx-2.1.11-53.el7.centos.x86_64
mailx-12.5-19.el7.x86_64

  1. 这里我使用的是163邮箱的SMTP服务,进入配置文件,在最后写入配置
set from=xxxxxxx@163.com		##邮件发送者
set smtp=smtps://smtp.163.com:465	##邮件服务器地址和端口
set ssl-verify=ignore			##忽略ssl认证
set nss-config-dir=/root/.certs		##证书存放路径
set smtp-auth-user=xxxxxx@163.com	##登录SMTP的用户名
set smtp-auth-password=xxxxxx		##登录SMTP的密码,这里需要使用授权码
set smtp-auth=login		#SMTP的认证方式

163邮箱的授权码获取方式
在这里插入图片描述

  1. 获取证书
mkdir -p /root/.certs/		##创建证书目录
cd /root/.certs
echo -n | openssl s_client -connect smtp.163.com:465 | sed -ne '/-BEGIN CERTIFICATE-/,/-END CERTIFICATE-/p' > ~/.certs/163.crt
certutil -A -n “GeoTrust SSL CA” -t “C,” -d ~/.certs -i ~/.certs/163.crt
certutil -A -n “GeoTrust Global CA” -t “C,” -d ~/.certs -i ~/.certs/163.crt
certutil -A -n “GeoTrust SSL CA - G3” -t “Pu,Pu,Pu” -d ~/.certs/./ -i 163.crt

chmod 777 * /root/.certs
[root@VM-0-2-centos .certs]# ll
total 64
-rwxrwxrwx 1 root root  2415 Jan 27 14:01 163.crt
-rwxrwxrwx 1 root root 65536 Jan 27 13:54 cert8.db
-rwxrwxrwx 1 root root 16384 Jan 27 13:54 key3.db
-rwxrwxrwx 1 root root 16384 Jan 27 13:54 secmod.db

 certutil -L -d /root/.certs 	##列出目录下证书
  1. 测试邮件发送
echo "456" |mail -s "test" XXXX@qq.com

在这里插入图片描述
如果发送未收到,检查证书获取是否有问题,重新获取尝试。

如果出现报错如:Error in certificate: Peer’s certificate issuer is not recognized. 再执行一次 “certutil -A -n “GeoTrust SSL CA - G3” -t “Pu,Pu,Pu” -d ./ -i 163.crt”

如果发送邮件被扔到垃圾箱或还是无法收到,可以在收件人邮箱添加白名单测试。

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

Howei__

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

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

余额充值