A boilerplate starter project for building a Java Spring Boot application with an E-mail Service. This template includes essential features for implementing an email service, such as sending emails, verifying email addresses, and resetting passwords.
- Send text-based emails
- Send templated emails
- Email templates using Thymeleaf
- Java 17+
- Maven
- Clone the repository:
git clone https://github.com/boilerlabs/java-spring-service-email
cd java-spring-service-email
- Configure the application properties in
src/main/resources/application.properties
:
spring.mail.host=myhost
spring.mail.port=587
spring.mail.username=myusername
spring.mail.password=mypassword
- Running with Maven
mvn spring-boot:run
The main feature of this project is the email service. The email service is implemented using the EmailService
class. This class is responsible for sending text-based emails, and templated emails.
We have also implemented the EmailController
class for you to test the email service. This controller has two endpoints:
To send a simple text email, send a POST request to /api/email/send
with the following JSON payload:
{
"to": "example_email",
"subject": "example_subject",
"body": "example_body"
}
To send a templated email, send a POST request to /api/email/send-template
with the following JSON payload:
{
"email": "example_email",
"username": "example_username"
}
The email templates are stored in the src/main/resources/templates
directory. The templates are written in Thymeleaf, a modern server-side Java template engine for web and standalone environments.
To create a new template, create a new HTML file in the src/main/resources/templates
directory. Here is the templates we have included in this project:
welcome-email.html
: A welcome email template that greets the user.verify-email.html
: A verify email template that allows the user to verify their email address.reset-password-email.html
: A reset password email template that allows the user to reset their password.marketing-email.html
: A marketing email template that promotes a product or service.
We welcome contributions! Please see the CONTRIBUTING.md for more details.
This project is licensed under the MIT License - see the LICENSE file for details.