程序问答   发布时间:2022-06-02  发布网站:大佬教程  code.js-code.com
大佬教程收集整理的这篇文章主要介绍了Spring Boot 1.2.5.RELEASE-通过Gmail SMTP发送电子邮件大佬教程大佬觉得挺不错的,现在分享给大家,也给大家做个参考。

如何解决Spring Boot 1.2.5.RELEASE-通过Gmail SMTP发送电子邮件?

开发过程中遇到Spring Boot 1.2.5.RELEASE-通过Gmail SMTP发送电子邮件的问题如何解决?下面主要结合日常开发的经验,给出你关于Spring Boot 1.2.5.RELEASE-通过Gmail SMTP发送电子邮件的解决方法建议,希望对你解决Spring Boot 1.2.5.RELEASE-通过Gmail SMTP发送电子邮件有所启发或帮助;

看起来Java Mail中存在回归/行为更改。更改同时在1.5.3和1.5.4中进行。您的应用程序使用Java Mail 1.5.2,因此可以与Boot 1.2.0一起使用。由于它使用Java Mail 1.5.4,因此在Boot 1.2.5中失败。

1.5.3+中的问题似乎是SMTP传输在端口465上连接,并且GMail需要SSL握手。Java Mail错误地认为它没有使用SSL,因此它从不发起握手并且连接尝试(最终)超时。您可以通过明确使用SSL来说服Java Mail做正确的事。将以下内容添加到application.propertIEs

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

解决方法

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>

Docs说: 如果spring.mail.host和相关的库(由spring-boot-starter-
mail定义)可用,则如果不存在默认JavaMailSender,则会创建一个默认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的所有优点。
请指出我的错误。

提前致谢

大佬总结

以上是大佬教程为你收集整理的Spring Boot 1.2.5.RELEASE-通过Gmail SMTP发送电子邮件全部内容,希望文章能够帮你解决Spring Boot 1.2.5.RELEASE-通过Gmail SMTP发送电子邮件所遇到的程序开发问题。

如果觉得大佬教程网站内容还不错,欢迎将大佬教程推荐给程序员好友。

本图文内容来源于网友网络收集整理提供,作为学习参考使用,版权属于原作者。
如您有任何意见或建议可联系处理。小编QQ:384754419,请注明来意。