弹簧启动1.2.5.RELEASE - 通过Gmail SMTP发送电子邮件 [英] Spring Boot 1.2.5.RELEASE - Sending E-mail via Gmail SMTP

查看:260
本文介绍了弹簧启动1.2.5.RELEASE - 通过Gmail SMTP发送电子邮件的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述


首先,我需要说,发送电子邮件与1.2.0.RELEASE工作正常

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>



将父版本更改为1.2.5.RELEASE发送电子邮件尚未生效

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

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


所以我添加了

<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

结果相同。


手动创建和配置@Bean不是问题。但是我想要使用Spring Boot的所有美丽。


请指出我的错误。

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.

提前感谢

推荐答案

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。

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.

1.5.3+中的问题似乎是SMTP传输连接在端口465和GMail希望SSL握手。 Java Mail错误地认为它不使用SSL,所以它永远不会启动握手,连接尝试(最终)超时。您可以说服Java Mail通过明确使用SSL来做正确的事情。将以下内容添加到 application.properties

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:

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

这篇关于弹簧启动1.2.5.RELEASE - 通过Gmail SMTP发送电子邮件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆