
Sending Emails through Spring Boot Application
Learn How to Send Emails in Spring Boot with JavaMailSender. Step-by-step guide to implement email integration using Spring Boot Starter Mail for real-world applications.

Munaf Badarpura
July 05, 2025
3 min read
Sending emails is a common requirement in real-world applications, whether it’s for account verification, password reset links, order confirmations, or simple notifications. Luckily, Spring Boot makes sending emails easy with minimal setup.
In this article, I will show you how to send emails using Spring Boot step by step. Whether you’re building a personal project or working on an enterprise application, this guide will help you integrate email functionality quickly.
Why Send Emails in Applications?#
Here are some common use-cases for sending emails:
- Account verification during user signup
- Password reset links for forgot password
- Order or booking confirmations
- Promotional or marketing emails
- System alerts or notifications
Spring Boot, with the help of JavaMailSender
interface, simplifies the process of sending emails from your application.
Here is Step-by-Step Guide to Send Emails with Spring Boot#
Add Spring Boot Mail Dependency#
First, add the Spring Boot Starter Mail dependency to pom.xml
:
If you’re using Gradle:
Configure Email Properties#
In your application.properties
or application.yml
file add your email server configurations. For this example, we will use Gmail SMTP, but you can use other providers as well.
Lets understand these configurations:#
- spring.mail.host=smtp.gmail.com : this tells Spring Boot which mail server to use. Here, we are using Gmail’s SMTP server, if you are using yahoo use, smtp.mail.yahoo.com.
- spring.mail.port=587 : the port number used for email transmission. Port
587
is the standard port for sending emails with STARTTLS security. - spring.mail.username=your_email@gmail.com : This is your Gmail account id that will be used to send emails.
- spring.mail.password=your_app_password : the password for your email account, here If you're using Gmail, you can’t use your normal account password here. You need to generate an App Password from your Google account settings for this to work securely.
- spring.mail.properties.mail.smtp.auth=true : It means your application will provide a username and password to log in to the mail server.
- spring.mail.properties.mail.smtp.starttls.enable=true : This enables STARTTLS, which adds a layer of security by encrypting the connection between your application and the mail server.
Create Email Service to Send Emails#
We’ll create a simple service class to send emails using JavaMailSender
.
Create a REST API to Trigger Email#
We can expose an endpoint to trigger the email for testing purposes.
You can now test the API using Postman or your browser using this API:
After hitting this API, the email will be sent to recipient email address that you pass in the toEmail
parameter.

Conclusion#
Sending emails with Spring Boot is simple and production-ready with minimal setup. With the combination of Spring Boot Starter Mail
and JavaMailSender
, you can integrate email functionality into your application.