22

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

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.


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.

Thanks in advance

Andy Wilkinson
  • 108,729
  • 24
  • 257
  • 242
InsFi
  • 1,298
  • 3
  • 14
  • 29
  • So what is the error message? – dunni Jul 30 '15 at 10:59
  • @dunni, There is not error message. Sender thread simply freezes – InsFi Jul 30 '15 at 11:01
  • So you have a sample project using Spring Boot 1.2.0 and it works. And then you just change to spring boot 1.2.5 and then it breaks? Nothing has changed between those two versions as far as I can see. Can you share the project? – Stephane Nicoll Jul 30 '15 at 11:28
  • @StéphaneNicoll , [link](https://github.com/levgaas/SpringBoot-emailer) I've replaced my credentials with ***. Now it's 1.2.0.RELEASE – InsFi Jul 30 '15 at 12:07

2 Answers2

38

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.

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
Andy Wilkinson
  • 108,729
  • 24
  • 257
  • 242
  • Worked for me as well. I had an additional error due to my antivirus. Once I disabled mail protection on it, the message was sent successfully – Juanal Jul 03 '16 at 11:39
  • This answer was very useful. I used it, along with the use of spring-boot's "spring.mail.test-connection=true", to quickly solve my issue. – Eric Spiegelberg Jan 06 '17 at 01:31
3

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

Stephane Nicoll
  • 31,977
  • 9
  • 97
  • 89