Ins*_*sFi 22 java email spring jakarta-mail spring-boot
首先,我需要说发送1.2.0.RELEASE的电子邮件工作正常
application.properties:
spring.mail.host = smtp.gmail.com
spring.mail.username = *****@gmail.com
spring.mail.password = ****
spring.mail.properties.mail.smtp.auth = true
spring.mail.properties.mail.smtp.socketFactory.port = 465
spring.mail.properties.mail.smtp.socketFactory.class = javax.net.ssl.SSLSocketFactory
spring.mail.properties.mail.smtp.socketFactory.fallback = false
Run Code Online (Sandbox Code Playgroud)
pox.xml
<parent>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-parent</artifactId>
<version>1.2.0.RELEASE</version>
<relativePath/>
</parent>
Run Code Online (Sandbox Code Playgroud)
.......
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-web</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-mail</artifactId>
</dependency>
Run Code Online (Sandbox Code Playgroud)
将父版本更改为1.2.5.RELEASE电子邮件发送无效
文档说: 如果spring.mail.host和相关库(由spring-boot-starter-mail定义)可用,则创建默认JavaMailSender(如果不存在).
所以我补充说
<dependency>
<groupId>javax.mail</groupId>
<artifactId>mail</artifactId>
<version>1.4.7</version>
</dependency>
Run Code Online (Sandbox Code Playgroud)
它没有帮助,然后我已经取而代之
<dependency>
<groupId>com.sun.mail</groupId>
<artifactId>javax.mail</artifactId>
<version>1.5.4</version>
</dependency>
Run Code Online (Sandbox Code Playgroud)
我也试过了
spring.mail.host = smtp.gmail.com
spring.mail.username = *****@gmail.com
spring.mail.password = ****
spring.mail.port = 465
Run Code Online (Sandbox Code Playgroud)
结果一样.
手动创建和配置@Bean不是问题.但是我想要使用Spring Boot的所有美感.
请指出我的错误.
提前致谢
And*_*son 36
看起来Java Mail中存在回归/行为变化.变化在1.5.3和1.5.4之间.您的应用程序使用Boot 1.2.0,因为它使用Java Mail 1.5.2.它使用Boot 1.2.5失败,因为它使用Java Mail 1.5.4.
1.5.3+中的问题似乎是SMTP传输在端口465上连接,而GMail需要SSL握手.Java Mail错误地认为它不使用SSL,因此它永远不会启动握手并且连接尝试(最终)超时.您可以通过明确使用SSL来说服Java Mail做正确的事情.将以下内容添加到application.properties
:
spring.mail.properties.mail.smtp.ssl.enable = true
Run Code Online (Sandbox Code Playgroud)
归档时间: |
|
查看次数: |
21216 次 |
最近记录: |