This project is a Spring Boot-based microservice designed to send emails using Amazon Simple Email Service (SES) ๐. It provides a RESTful API to trigger email sending through HTTP requests, following a clean architecture pattern with clear separation of concerns. The microservice is lightweight, scalable, and perfect for integration in a microservices ecosystem ๐.
- Send emails using Amazon SES with customizable recipient, subject, and body ๐ฉ.
- RESTful API endpoint to trigger email sending via POST requests ๐.
- Clean architecture with separation of concerns (use cases, application, adapters, infrastructure) ๐งฉ.
- Error handling for email sending failures ๐จ.
- Configurable email source address via environment properties โ๏ธ.
- Integration with AWS SES for reliable email delivery โ๏ธ.
- Java โ: Programming language (version 11 or later).
- Spring Boot ๐ฑ: Framework for building the microservice.
- Amazon SES โ๏ธ: Email sending service via AWS SDK.
- Maven ๐ฆ: Dependency management and build tool.
- Spring Web ๐ธ๏ธ: For creating RESTful endpoints.
- Spring Core ๐ฉ: For dependency injection and configuration.
- AWS SDK for Java ๐ ๏ธ: To interact with Amazon SES.
Before running the project, ensure you have:
- Java Development Kit (JDK) 11 or higher โ.
- Maven 3.6 or higher ๐ฆ.
- An AWS account with access to Amazon SES โ๏ธ.
- AWS credentials (Access Key ID and Secret Access Key) with SES permissions ๐.
- Git (optional, for cloning the repository) ๐.
-
Clone the Repository:
git clone https://github.com/Mirian97/email-microservice-spring-boot.git cd email-microservice-spring-boot -
Install Dependencies:
./mvnw clean install
-
Configure AWS SES:
- Set up your AWS SES account and move out of sandbox mode for production (or use sandbox for testing) โ๏ธ.
- Obtain your AWS Access Key ID and Secret Access Key from the AWS IAM console ๐.
- Verify an email address in SES to use as the
emailSource๐ง.
-
Update Configuration: Configure the
application.propertiesfile (see ๐ง Configuration section). -
Run the Application:
./mvnw spring-boot:run
The app starts on
http://localhost:8080by default.
Update src/main/resources/application.properties or application.yml with your AWS credentials and email source. Example:
emailSource=verified-email@example.com
aws.accessKeyId=your-aws-access-key-id
aws.secretKey=your-aws-secret-key
aws.region=us-your-aws-region
springdoc.api-docs.path=/swagger-ui.html
springdoc.swagger-ui.enabled=true
springdoc.api-docs.path=/api-docsFor security, use environment variables or AWS Secrets Manager in production ๐.
If your your project is already running, you could check an online documentation with Swagger OpenApi, in this link http://localhost:8080/swagger-ui/index.html
Sends an email with the provided details ๐ฉ.
JSON format:
{
"to": "string",
"subject": "string",
"body": "string"
}to: Recipient's email address ๐จ.subject: Email subject line โ๏ธ.body: Email body content (plain text) ๐.
- Success โ
:
200 OK"Email sent successfully" - Error โ:
500 INTERNAL SERVER ERROR"Error when sending email: <error-message>"
curl -X POST http://localhost:8080/api/email \
-H "Content-Type: application/json" \
-d '{
"to": "recipient@example.com",
"subject": "Test Email",
"body": "This is a test email sent via AWS SES."
}'- Start the application as described in โ๏ธ Setup and Installation.
- Send a POST request to
/api/emailusingcurl, Postman, or any HTTP client ๐ฌ. - Verify the response to confirm email sending โ .
- Check the recipient's inbox (if verified in SES) or SES console for delivery status ๐.
- EmailServiceException: Handles email sending failures (e.g., invalid addresses, SES errors)
โ ๏ธ . - AmazonServiceException: Wrapped in
EmailServiceExceptionfor AWS-specific issues (e.g., authentication, limits) โ๏ธ. - Returns
500 INTERNAL SERVER ERRORwith a descriptive message on failure โ.
The project follows a clean architecture pattern:
- Core ๐ง :
EmailSenderUseCase: Defines email sending contract.EmailRequest: Record for email data (to, subject, body).EmailServiceException: Custom exception for errors.
- Application โ๏ธ:
EmailSenderService: ImplementsEmailSenderUseCase, delegates to gateway.
- Adapter ๐:
EmailSenderGateway: Interface for email sending implementation.
- Infrastructure ๐๏ธ:
SesEmailSender: Uses AWS SES to send emails.AwsSesConfig: Configures SES client with credentials and region.
- Controller ๐ฎ:
EmailSenderController: Handles HTTP requests and delegates to service.
This ensures modularity, testability, and flexibility to swap email providers.
