欢迎访问 生活随笔!

生活随笔

当前位置: 首页 > 编程资源 > 编程问答 >内容正文

编程问答

云服务器如何发送邮件

发布时间:2024/8/1 编程问答 38 豆豆
生活随笔 收集整理的这篇文章主要介绍了 云服务器如何发送邮件 小编觉得挺不错的,现在分享给大家,帮大家做个参考.

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

操作如下:

  • 进入云服务器,检测是否安装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
  • 这里我使用的是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邮箱的授权码获取方式

  • 获取证书
  • 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.crtchmod 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.dbcertutil -L -d /root/.certs ##列出目录下证书
  • 测试邮件发送
  • 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”

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

    总结

    以上是生活随笔为你收集整理的云服务器如何发送邮件的全部内容,希望文章能够帮你解决所遇到的问题。

    如果觉得生活随笔网站内容还不错,欢迎将生活随笔推荐给好友。