How to Send Mail Spring Boot Example

By | August 1, 2021

In this post, We will learn How to Send Mail Spring Boot Example using a demo Project.

Spring Boot Starter email is a generally thin wrapper over Jakarta Mail API that makes very easy integration with emailing services into Spring-based applications. so here we will be using Spring starter email dependency in pom.xml to work with email functionality.

We will be adding below Spring boot starter email dependency to work with sending a mail from the spring boot application in maven based project.


In Order to send mail, we have to Configure SMTP Properties in the application’s properties file as below.

We have configured Gmail’s SMTP server details with SMTP TLS enable as true. Here as per your requirement, If you can also configure the settings of your own SMTP server. In case you are using Gmail then you must enable SMTP in your Gmail profile/account settings to generate an access password (not your email password) for better security reason.

Spring Mail API has a JavaMailSender interface that gives important methods for sending emails. After configuring SMTP server details in our Application’s properties file, We can ask Spring framework to inject the default implementation of JavaMailSender into an EmailSenderService class like this:

In the below Spring BootStrap class, we are asking Spring Container to return EmailSenderService bean so that we can invoke sendEmail(-,-,-,-)  method to test email functionality.

That’s all about How to Send Mail Spring Boot Example

You May Also Like:

What is Spring boot ?
Spring vs Spring boot
Spring Boot Actuator
How to Configure Multiple Data Sources in a Spring Boot?
Spring BeanFactory Container Example
Spring ApplicationContext Container Example
Annotation-based Configuration in Spring Framework Example
Spring Java-based Configuration Example
Spring Setter Dependency Injection Example
Spring @Autowired Annotation With Setter Injection Example
Spring Constructor based Dependency Injection Example
Spring @Autowired Annotation With Constructor Injection Example

If you have any feedback or suggestion please feel free to drop in below comment box.

Leave a Reply

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