Send Email Using Spring Boot
Hello everyone, today we will learn how to send an email via SMTP in Spring Boot.
Technologies used:
- Spring Boot 2.1.1.RELEASE
- Java Mail 1.6.2
- Maven 3
- Java 8
Project Structure:
Dependency Managemen(pom.xml):
spring-boot-starter-mail will pull the JavaMail dependencies.
Spring Boot Mail Server Properties
Once the dependency is in place, the next step is to specify the mail server properties in the application.properties file using the spring.mail.* namespace.
Sending Email
Spring provides a JavaMailSender interface on top of JavaMail APIs.
Main class
Start Spring Boot, and it will send out an email.
Local Setup:
Step 1: Download or clone the source code to a local machine.
Step 2: mvn clean install
Step 3: Run the Spring Boot applicationmvn spring-boot:run
mvn spring-boot:run
Terminal
. ____ _ __ _ _
/\\ / ___'_ __ _ _(_)_ __ __ _ \ \ \ \
( ( )\___ | '_ | '_| | '_ \/ _` | \ \ \ \
\\/ ___)| |_)| | | | | || (_| | ) ) ) )
' |____| .__|_| |_|_| |_\__, | / / / /
=========|_|==============|___/=/_/_/_/
Ready to sent an email
Successfully dropped an email
Download Source Code