To build and run the application, you will need Java and Docker preinstalled.
$ git clone https://github.com/zh-efimenko/Mailer.git
$ cd Mailer
$ ./gradlew build- Set up AUTHORIZATION_TOKEN, your gmail credentinals MAIL_USERNAME, MAIL_PASSWORD
$ docker-compose up -d$ docker run -d --name mailer --restart always \
-v $DATA_DIR:/data/ \
-e AUTHORIZATION_TOKEN=$AUTHORIZATION_TOKEN \
-e MAIL_USERNAME=$MAIL_USERNAME \
-e MAIL_PASSWORD=$MAIL_PASSWORD \
eefimenko/mailerversion: '3'
services:
rabbitmq:
image: rabbitmq:3-management
restart: always
ports:
- 15672:15672
- 5672:5672
mailer:
depends_on:
- rabbitmq
build:
context: .
dockerfile: /docker/Dockerfile
image: eefimenko/mailer
environment:
AUTHORIZATION_TOKEN: '&d5yNc6FkoB0'
MAIL_USERNAME: 'username@gmail.com'
MAIL_PASSWORD: 'password'
RABBITMQ_ENABLE: 'true'
RABBITMQ_HOST: rabbitmq
ports:
- 8080:8080
restart: always
volumes:
- ./data:/data
The Application uses several environment variables.
In order to send attachments with message to need to encode them to base64.
Application can set up with any email provider: Google, Yandex, others.
AUTHORIZATION_TOKEN
Set the AUTHORIZATION_TOKEN lets the application to access to your application. The put AUTHORIZATION_TOKEN to HTTP header is Autorization.
MAIL_USERNAME&MAIL_PASSWORD
Set the MAIL_USERNAME and MAIL_PASSWORD environment variable with the email and password for your email provider.
Next variables can be changed if needed.
MAIL_HOST
Set the MAIL_HOST environment variable for override default: smtp.gmail.com
MAIL_PORT
Set the MAIL_PORT environment variable for override default: 587
MAIL_PROTOCOL
Set the MAIL_PROTOCOL environment variable for override default: smtp
MAIL_DEFAULT_ENCODING
Set the MAIL_DEFAULT_ENCODING environment variable for override default: UTF-8
MAIL_PROPERTIES
Set the MAIL_PROPERTIES environment variable for override default: mail.smtp.starttls.enable=true,mail.smtp.starttls.required=true
RABBITMQ_ENABLE
Set the RABBITMQ_ENABLE environment variable for enable RabbitMQ, default: false
RABBITMQ_EXCHANGER
Set the RABBITMQ_EXCHANGER environment variable to create exchanger, default: mailer
RABBITMQ_QUEUE
Set the RABBITMQ_QUEUE environment variable to create queue, default: mailer
RABBITMQ_ROUTING_KEY
Set the RABBITMQ_ROUTING_KEY environment variable to create routing-key, default: mailer-key
RABBITMQ_HOST
Set the RABBITMQ_HOST environment variable for override default: localhost
RABBITMQ_PORT
Set the RABBITMQ_PORT environment variable for override default: 5672
RABBITMQ_DEFAULT_VHOST
Set the RABBITMQ_DEFAULT_VHOST environment variable for override default: /
RABBITMQ_DEFAULT_USER
Set the RABBITMQ_DEFAULT_USER environment variable for override default: guest
RABBITMQ_DEFAULT_PASS
Set the RABBITMQ_DEFAULT_PASS environment variable for override default: guest
In order to send message you need to create the follow json:
{
"from": {
"address": "from@mail.ru",
"personal": "personal"
},
"to": [
{
"address": "to@mail.ru",
"recipientType": "{TO|CC|BCC}"
}
],
"subject": "Subject",
"message": "message",
"type": "{mail-message}"
}Response:
{
"status": "{OK|FAIL}"
}In order to send message by template you need to create the follow json:
{
"from": {
"address": "from@mail.ru",
"personal": "personal"
},
"to": [
{
"address": "to@mail.ru",
"recipientType": "{TO|CC|BCC}"
}
],
"subject": "Subject",
"template": {
"namespace": "Namespace",
"name": "template.ftl",
"content": {
"name": "name",
"link": "link"
}
},
"type": "{mail-template}"
}Response:
{
"status": "{OK|FAIL}"
}In order to send template you need to create the follow json:
{
"namespace": "Namespace",
"name": "confirmation.ftl",
"body": "base64(body)",
"type": "{template}"
}Response:
{
"status": "{OK|FAIL}"
}In order to enhance your opportunities in frontend and microservices development to use Swagger.
To get Mailer API follow the url:
http://{host}/swagger-ui.html
