Skip to content

POC that sends emails to user on account creation event occurrence: made using java spring boot, apache freemarker, java-mail-API, bootstrap email editor and spring events.

Notifications You must be signed in to change notification settings

hardikSinghBehl/spring-boot-freemarker-java-mail-api

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

22 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Hedwig

Proof-of-concept application to send emails to user on event occurence

Click Here To Use Running Application

Technologies Used

  • Java Spring Boot
  • JavaMail-API
  • Spring Events
  • Apache Freemarker
  • JPA/H2 in-memory database
  • Lombok
  • Open-API (swagger-ui)
  • Bootstrap-Email Editor

Spring Events

  • Reference Article
  • Event classes will represent an event for which a mail has to be sent (account-creation-event in this context can be anything depending on business logic)
  • A listener class that listens to the above created event and executes code whenever the above event occures
  • A publisher will publish the event (notify that event has occurred) and can be injected in the service layer
  • Listener method to be executed asynchronously (recommended)

Main classes (Drag to new window)

Bootstrap Email

  • HTML for emails is slightly different from HTML for web
  • Copy the HTML generated from bootstrap email editor (right part of screen) to a .ftl file under src/main/resources/templates (configured in FreemarkerConfiguration.class)
  • account-creation-success.ftl in templates folder will be generated to the below image
  • ${emailId} and ${fullName} will be converted to provided emailId and fullname with the help of apache freemarker

mail

Local Setup

  • Install Java 15
  • Install Maven

Recommended way is to use sdkman for installing both maven and java

Go to application.properties and configure your email and app password (diffrent from regular passwords)

spring.mail.username = <EMAIL-ID-HERE>
spring.mail.password = <PASSWORD-HERE>

Run the below commands in the core

mvn clean install
mvn spring-boot:run

server port is configured to 9090 and base-url to /hedwig which can be changed in application.properties file

Go to the below url to view swagger-ui (API docs)

http://localhost:9090/hedwig/swagger-ui.html

Run Tests

mvn test

About

POC that sends emails to user on account creation event occurrence: made using java spring boot, apache freemarker, java-mail-API, bootstrap email editor and spring events.

Topics

Resources

Stars

Watchers

Forks

Packages

No packages published

Languages