Microservice Email is a service developed in Java with Spring Boot, designed to simplify email sending through Gmail. This microservice provides an efficient and scalable solution for integrating email sending functionalities into your applications, utilizing the reliable infrastructure of Gmail as the SMTP server.
Before running the application, ensure you have the following prerequisites installed.
- Git: Widely-used distributed version control system.
- Java 17: A stable version of the Java Development Kit (JDK).
- Docker: A platform for developing, shipping, and running applications in containers.
git clone https://github.com/esperanca-leonardo/microservice-email.git
cd microservice-email
This project uses Gmail for sending emails. You will need to generate an app password for your Gmail account. Follow the instructions here to generate an app password.
Before utilizing this project, it's crucial to configure certain environment variables on your system. To simplify this process, default values are provided as follows.
SERVER_PORT=8080
MAIL_HOST=smtp.gmail.com
MAIL_PORT=587
[email protected]
MAIL_PASSWORD=your_app_password
DATABASE_HOST=localhost
DATABASE_PORT=5432
DATABASE_NAME=microservice_email
DATABASE_USER=user
DATABASE_USER_PASSWORD=123
-
Before proceeding with the instructions below, please remember to change the values of the following environment variables according to your credentials:
MAIL_USERNAME
,MAIL_PASSWORD
. -
To make the setup process more easier, you can use a script to automatically configure these environment variables. Below are instructions and scripts for Windows and Linux systems.
-
For Windows, you can use a batch script to set the environment variables. Create a file named
set_env_vars.bat
with the following content.@echo off setx SERVER_PORT 8080 setx MAIL_HOST smtp.gmail.com setx MAIL_PORT 587 setx MAIL_USERNAME [email protected] setx MAIL_PASSWORD "your_app_password" setx DATABASE_HOST localhost setx DATABASE_PORT 5432 setx DATABASE_NAME microservice_email setx DATABASE_USER user setx DATABASE_USER_PASSWORD 123
To run the script, double-click the
set_env_vars.bat
file or execute the below command in the terminal..\set_env_vars.bat
-
For Linux, you can use a shell script to set the environment variables. Create a file named
set_env_vars.sh
with the following content.#!/bin/bash if [ -f ~/.bashrc ]; then echo "export SERVER_PORT=8080" >> ~/.bashrc echo "export MAIL_HOST=smtp.gmail.com" >> ~/.bashrc echo "export MAIL_PORT=587" >> ~/.bashrc echo "export [email protected]" >> ~/.bashrc echo "export MAIL_PASSWORD='your_app_password'" >> ~/.bashrc echo "export DATABASE_HOST=localhost" >> ~/.bashrc echo "export DATABASE_PORT=5432" >> ~/.bashrc echo "export DATABASE_NAME=microservice_email" >> ~/.bashrc echo "export DATABASE_USER=user" >> ~/.bashrc echo "export DATABASE_USER_PASSWORD=123" >> ~/.bashrc else echo "~/.bashrc file not found. Variables not defined." exit 1 fi
To execute the script, navigate to the directory containing
set_env_vars.sh
and run the following command.chmod u+x set_env_vars.sh && ./set_env_vars.sh
After running the script, remember to apply the changes by executing
source ~/.bashrc
-
This project is facilitated by a docker-compose.yml file, encapsulating all the essential configurations to bootstrap the database infrastructure. Copy and paste the command below into the terminal to start the database.
docker-compose up -d
Depending on your operating system, execute the commands below to start the application.
-
Utilize the Maven Wrapper to run the application on Windows.
.\mvnw.cmd spring-boot:run
-
Grant executable permissions to the Maven Wrapper and initiate the application on Linux.
chmod u+x mvnw && ./mvnw spring-boot:run