说明:

出于安全考虑,阿里云默认封禁 TCP 25 端口出方向的访问流量,无法在阿里云上的云服务器通过 TCP 25 端口连接外部地址。

【官方提示】:如果您需要使用阿里云上的云服务器对外部发送邮件,建议您使用阿里云邮产品或者使用第三方邮件服务商提供的 465 端口。记得添加安全组配置

如果你确实需要使用 25 端口,可在安全管控平台中提交25端口解封申请,地址:https://help.aliyun.com/knowledge_detail/56130.html

但修改为 465 端口后发送邮件会报错

报错信息如下:

org.springframework.mail.MailSendException: Mail server connection failed; nested exception is javax.mail.MessagingException: Could not connect to SMTP host: smtp.qq.com, port: 465, response: -1. Failed messages: javax.mail.MessagingException: Could not connect to SMTP host: smtp.qq.com, port: 465, response: -1

解决办法:

在 application.yml 中将邮件配置为 SSL 连接

spring:
mail:
host: smtp.qq.com
username: 你的邮箱账号
password: 你的邮箱授权码(QQ邮箱)
port: 465
protocol: smtp
default-encoding: utf-8
properties:
mail:
smtp:
auth: true
starttls:
enable: true
required: true
ssl:
enable: true
socketFactory:
port: 465
class: javax.net.ssl.SSLSocketFactory

如果你使用的是 properties 文件,应该修改为:

# JavaMailSender 配置
spring.mail.host=smtp.qq.com
spring.mail.username=你的邮箱账号
spring.mail.password=你的邮箱授权码(QQ邮箱)
spring.mail.port=465
spring.mail.default-encoding=utf-8
spring.mail.properties.mail.smtp.auth=true
spring.mail.properties.mail.smtp.starttls.enable=true
spring.mail.properties.mail.smtp.starttls.required=true
# SSL 配置
spring.mail.protocol=smtp
spring.mail.properties.mail.smtp.ssl.enable=true
spring.mail.properties.mail.smtp.socketFactory.port=465
spring.mail.properties.mail.smtp.socketFactory.class=javax.net.ssl.SSLSocketFactory

推荐一个 yml、properties 文件在线转换的网站 https://toyaml.com/index.html

最新文章

  1. Windows进程间通信—命名管道
  2. iOS 面试题搜集
  3. 作业七:团队项目——Alpha版本冲刺阶段005
  4. Android开发小问题记录
  5. hdu 4010 动态树 @
  6. 【转】PowerShell入门(五):Cmd命令与PowerShell命令的交互
  7. python多线程threading
  8. cocos2d-x知识巩固-基础篇(1)
  9. mysqldump的常用语句及各参数详解
  10. ES聚合实例
  11. 深度学习:Keras入门(二)之卷积神经网络(CNN)
  12. Srping - bean的依赖注入(Dependency injection)
  13. 爬虫——xpath
  14. Struts1 不能进入Action,页面空白问题解决
  15. Mysql优化系列--Innodb引擎下mysql自身配置优化-转
  16. EasyUI tree reload时更改参数的问题。
  17. PreviewRenderUtility的Example
  18. C#学习笔记(27)——委托排序(1)
  19. FMX StringGrid向上滑动自动加载记录(二)
  20. 九度 1500:出操队形(LIS变形)

热门文章

  1. Vue错误信息解决
  2. 831. KMP字符串
  3. 恭祝2018元旦快乐!转发享福利(⊙o⊙)…
  4. 烘焙ID贴图
  5. VMWare vCenter 4.x 数据库由SQL Express 迁移至SQL Server 2008 R2
  6. JavaScript中如何给按钮设置隐藏与显示属性
  7. js操作复选框
  8. KEMET新型电容器推动了电动汽车技术的发展
  9. SpringBoot图文教程11—从此不写mapper文件「SpringBoot集成MybatisPlus」
  10. 7-1 jmu-python-汇率兑换 (10 分)