Click Here To Use Running Application
- Java Spring Boot
- JavaMail-API
- Spring Events
- Apache Freemarker
- JPA/H2 in-memory database
- Lombok
- Open-API (swagger-ui)
- Bootstrap-Email Editor
- 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)
- Email-Service (to send emails to provided email-id with provided template and subject)
- Account Creation Event
- Account Creation Event Listener (receives userCreationRequestDto as input and sends mail to provided email-id asynchronously)
- User Service (class that creates user account in the system and publishes that AccountCreationEvent has occurred)
- 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
- 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