This project is designed to send emails to multiple users simultaneously to multiple recipients across different email platforms, including Gmail and Outlook.
- Simultaneous Email Sending : Send emails to many recipients in a single action.
- Multi-Client Compatibility : Supports Gmail, Outlook, and other email services.
- java 21 : The programming language used for developing the application.
- ** Spring Version :**
Spring 3.2.8
The framework used to build and run the application. - Spring Web : Used to implement stateless URLs in web applications.
- aspect : Designed to handle multiple parts of an application, such as logging .
- actuator : using to monitoring application .
- swagger : use to implement documentation to your project
- Maven : The build automation tool used for managing project dependencies and building the application.
- SMTP Server : Sends emails using Google’s SMTP server with your personal email.
- Exeption handler : Provides custom error messages for different types of exceptions in one place.
- **
.env
secret management :** use to secret the sensitive information - yml File : the project use YAML file to handle Configuration
- java 21
- Maven
- spring boot
- SMTP Server
To run the project, you need to configure an email SMTP server. For this demo, we are using Google SMTP.
- Go to this link and log in with your Google account.
- If you are informed that your account is unavailable for this service, follow these steps:
- Go to your account settings.
- Enable "2-Step Verification."
This will allow you to create an App Password for your SMTP configuration.
HOST=smtp.gmail.com
PORT=smtp_port
USERNAME=your_email_address_setup_with_provider
PASSWORD=your_generated_password
- **Port
587
** : For TLS/STARTTLS (recommended for most email clients). - **Port
465
** : For SSL (less commonly used).
- If you are using Google SMTP, do not change this value:
smtp.gmail.com
.
- USERNAME : Enter the email address you used to create the App Password.
- PASSWORD : Enter the password that you generated above.
- In this project, I used
IntelliJ
. - To run the application, go to the class
SenderEmailApplication
and clickRun
.
There are two ways to interact with the project to send emails to multiple users:
- Swagger
- Postman
In this demo, we will explain how to interact with the project using Swagger
.
To access Swagger, use the following link: http://localhost:8080/swagger-ui/index.html#/.
- you will see only one endPoint
POST
http://localhost:8080/email/send-email
This endpoint allows you to send an email to one or more recipients. Here’s how it works:
The request body must include the following fields:
to
: List of recipient email addresses .- At least one email address is required.
- Email addresses must follow a valid email format.
subject
: The subject of the email.- This field must not be null.
body
: The content of the email.- This field must not be null.
If any of the following fields are null or empty:
to
subject
body
The server will return a 400 Bad Request
error with an appropriate exception message.
{
"body": " this is body",
"subject": "subject of email",
"to": [
"mo********4@gmil.com"
]
}
{
"body": {
"body": " this is body",
"subject": "subject of email",
"to": [
"mo********4@gmil.com"
]
},
"message": "Email has been sent successfully ",
"statusCode": "ACCEPTED"
}
{
"body": " ",
"subject": " this is a subject",
"to": [
"mo********4@gmil.com"
]
}
{
"body": null,
"message": "Error: The body of the email is empty.",
"statusCode": "BAD_REQUEST"
}
{
"body": " this is a body ",
"subject": " ",
"to": [
"mo********4@gmil.com"
]
}
{
"body": null,
"message": "Error: The subject of the email is empty.",
"statusCode": "BAD_REQUEST"
}
{
"body": " this is a body ",
"subject": " this is a subject ",
"to": [
"Team Zero "
]
}
{
"body": null,
"message": "Error: One or more recipient email addresses are invalid.",
"statusCode": "BAD_REQUEST"
}