弹簧引导1.2.5。释放-通过Gmail SMTP发送电子邮件。

时间:2022-11-15 10:48:47

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

首先,我需要说,用1.2.0发送电子邮件。释放工作正常

application.properties:

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

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

将父版本更改为1.2.5。发送邮件没有成功。

Docs says: If spring.mail.host and the relevant libraries (as defined by spring-boot-starter-mail) are available, a default JavaMailSender is created if none exists.

医生说:如果spring.mail。主机和相关库(由spring-boot-starter-mail定义)是可用的,如果不存在,就会创建一个默认的JavaMailSender。


So i've added

我添加了

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

It hasn't helped and then i've replaced it to

它没有帮助,然后我把它换成了。

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

Also i've tried

我也试过

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

Result the same.

It's not a problem to create and configure @Bean manually. But I want to use all beauty of Spring Boot.
Please point me to my mistakes.

结果是一样的。手动创建和配置@Bean不是问题。但我想用所有的春装美。请指出我的错误。

Thanks in advance

谢谢提前

2 个解决方案

#1


34  

It looks like there's a regression/behaviour change in Java Mail. The change is in both 1.5.3 and 1.5.4. Your app works with Boot 1.2.0 as it uses Java Mail 1.5.2. It fails with Boot 1.2.5 as it uses Java Mail 1.5.4.

看起来Java邮件中出现了回归/行为变化。变化在1.5.3和1.5.4中。您的应用程序使用的是Boot 1.2.0,因为它使用的是Java邮件1.5.2。在使用Java邮件1.5.4时,它的Boot 1.2.5失败。

The problem in 1.5.3+ appears to be that the SMTP transport connects on port 465 and GMail expects an SSL handshake. Java Mail incorrectly thinks it's not using SSL so it never initiates the handshake and the connection attempt (eventually) times out. You can convince Java Mail to do the right thing by being explicit about the use of SSL. Add the following to application.properties:

1.5.3+中的问题似乎是SMTP传输在端口465上连接,而GMail则需要SSL握手。Java Mail错误地认为它没有使用SSL,所以它从不发起握手和连接尝试(最终)超时。通过明确使用SSL,您可以说服Java邮件做正确的事情。添加以下应用程序。属性:

spring.mail.properties.mail.smtp.ssl.enable = true

#2


3  

It looks like it is a regression. I have created #3624 to investigate the issue. Thanks for the sample project!

看起来像是回归。我已经创建了#3624来调查这个问题。感谢您的样例项目!

#1


34  

It looks like there's a regression/behaviour change in Java Mail. The change is in both 1.5.3 and 1.5.4. Your app works with Boot 1.2.0 as it uses Java Mail 1.5.2. It fails with Boot 1.2.5 as it uses Java Mail 1.5.4.

看起来Java邮件中出现了回归/行为变化。变化在1.5.3和1.5.4中。您的应用程序使用的是Boot 1.2.0,因为它使用的是Java邮件1.5.2。在使用Java邮件1.5.4时,它的Boot 1.2.5失败。

The problem in 1.5.3+ appears to be that the SMTP transport connects on port 465 and GMail expects an SSL handshake. Java Mail incorrectly thinks it's not using SSL so it never initiates the handshake and the connection attempt (eventually) times out. You can convince Java Mail to do the right thing by being explicit about the use of SSL. Add the following to application.properties:

1.5.3+中的问题似乎是SMTP传输在端口465上连接,而GMail则需要SSL握手。Java Mail错误地认为它没有使用SSL,所以它从不发起握手和连接尝试(最终)超时。通过明确使用SSL,您可以说服Java邮件做正确的事情。添加以下应用程序。属性:

spring.mail.properties.mail.smtp.ssl.enable = true

#2


3  

It looks like it is a regression. I have created #3624 to investigate the issue. Thanks for the sample project!

看起来像是回归。我已经创建了#3624来调查这个问题。感谢您的样例项目!