How to configure JavaMailSender with SpringBoot

Spring Framework provides JavaMailSender interface & Spring Boot provides auto-configuration for it. So in the tutorial, JavaSampleApproach will introduce how to configure JavaMailSender to send a gmail by a sample code.

I. Technologies

– Java 1.8
– Maven 3.3.9
– Spring Tool Suite – Version 3.8.1.RELEASE
– Spring Boot: 1.5.1.RELEASE

II. Practice

Step to do
– Create SpringBoot project
– Create MailSender
– Develop a test client
– Run & check results

1. Create SpringBoot project

– Using SpringToolSuite, create a SpringBoot project. Then add spring-boot-starter-mail dependency:

2. Create MailSender

– Firstly, open file, configure spring.mail for JavaMailSender:

– Create a MailSender class:

3. Develop a test client

In main class of SpringBoot App, implements CommandLineRunner interface:

4. Run & check results

– Build & Run the project with SpringBoot App mode.

If you get below error:

>>> How to resolve it?
Gmail account is highly secured. So Email is blocked. The solution is to make the gmail account less secure:
– Login to Gmail.
– Access
– Select “Turn on”

III. Sourcecode


By JavaSampleApproach | April 15, 2017.

Related Posts

1 thought on “How to configure JavaMailSender with SpringBoot”

  1. Your blog actually helpful for email sending. I am looking for the security solution rather than making Gmail account less secure is it possible to make it with OAuth2 Authentication using springboot java email starter

Got Something To Say:

Your email address will not be published. Required fields are marked *