This application developed for make container application.
Basically there exist one endpoint. Post an object, send mail and insert database.
In this application you can create containers (database, application).
The project is built on Spring Boot architecture. Maven used as build automation tool.
Firstly you need to update your mail server configurations. File Path : application.yml
spring:
mail:
host: smtp.gmail.com
port: 587
username: ${MAIL_ADDRESS}
password: ${MAIL_PASSWORD}
properties:
mail:
smtp:
auth: true
starttls:
enable: true
required: true
ssl:
trust: smtp.gmail.com ./mvnw package -Dspring-boot.run.profiles=tst -DskipTests After package completed, packaged application : spring-mail-0.0.1.jar
If you want to install or package with Test parts, you need e valid database before. You can run below command with valid database
./mvnw -DSPRING_DATASOURCE_URL=jdbc:mysql://localhost:3306/mail-database install Firstly need to create a docker file detailed below.
Path : Dockerfile
FROM openjdk:8-jdk-alpine
MAINTAINER workshop.com
COPY target/spring-mail-0.0.1.jar spring-mail.jar
ENTRYPOINT ["java","-jar","/spring-mail.jar"] docker build --tag=spring-mail:latest .File Path : docker-compose.yml
Related SQL in this path : create_database.sql
spring-mail-application:
environment:
SPRING_DATASOURCE_URL: jdbc:mysql://mysql-database:3306/mail-database?autoReconnect=true&useSSL=false
MAIL_ADDRESS: **mail address**
MAIL_PASSWORD: **mail password**you need to give access to anonymous request at google accounts security settings
docker-compose -f "docker-compose.yml" up -d --build version: '3.8'
networks:
default:
services:
mysql-database:
image: mysql:5.7
container_name: mysql-database
ports:
- 3306:3306
volumes:
- ./sql/create_database.sql:/docker-entrypoint-initdb.d/create_database.sql
environment:
MYSQL_ROOT_PASSWORD: pass
spring-mail-application:
image: spring-mail:latest
container_name: spring-mail-app
restart: on-failure
environment:
SPRING_DATASOURCE_URL: jdbc:mysql://mysql-database:3306/mail-database?autoReconnect=true&useSSL=false
MAIL_ADDRESS: mail address
MAIL_PASSWORD: mail password
depends_on:
- mysql-database
ports:
- 8080:8080
restart: on-failure at the first try for up, couldn't connect to db. With this command restart application and successfully connect.
With this endpoint, requester can send email with valid spring mail configurations.
{
"applicationName" : "spring-mail",
"subject": "Hello World!",
"to": "mail@mail.com",
"body": "Hello World!"
}{
"result": true,
"message": "Mail Successfully Sent"
}
