gpt4 book ai didi

java - Spring Boot 1.2.5.RELEASE - 通过 Gmail SMTP 发送电子邮件

转载 作者:IT老高 更新时间:2023-10-28 13:48:36 26 4
gpt4 key购买 nike

Firstly, I need to say that sending email with 1.2.0.RELEASE works fine

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

pox.xml

<parent>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-parent</artifactId>
<version>1.2.0.RELEASE</version>
<relativePath/>
</parent>

.......

<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>


After changing parent version to 1.2.5.RELEASE email sending hasn't worked

文档说:如果 spring.mail.host 和相关库(由 spring-boot-starter-mail 定义)可用,如果不存在,则创建默认 JavaMailSender。


所以我添加了

<dependency>
<groupId>javax.mail</groupId>
<artifactId>mail</artifactId>
<version>1.4.7</version>
</dependency>

它没有帮助,然后我将其替换为

<dependency>
<groupId>com.sun.mail</groupId>
<artifactId>javax.mail</artifactId>
<version>1.5.4</version>
</dependency>

我也试过

spring.mail.host = smtp.gmail.com
spring.mail.username = *****@gmail.com
spring.mail.password = ****
spring.mail.port = 465

结果相同。

手动创建和配置@Bean 不是问题。但我想使用 Spring Boot 的所有优点。
请指出我的错误。

提前致谢

最佳答案

Java Mail 中似乎存在回归/行为变化。 The change在 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

关于java - Spring Boot 1.2.5.RELEASE - 通过 Gmail SMTP 发送电子邮件,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/31721298/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com