Email sender microservice
This is a proof of concept. A RESTful microservice to send e-mails using smtp credentials.
It's necessary to create the .env
file:
cp .env.template .env
And fill DEFAULT_TO_ADDRESS
, FROM_ADDRESS
and EMAIL_PASSWORD
variables.
make build
make up
GET to http://0.0.0.0:3000/emails/
Returns a list of all created e-mails.
URL parameters:
limit: int (optional)
Determines the number of emails that should be shown. Default value is 10 and can be changed setting DEFAULT_LIMIT
in the .env
file.
sent: true|false (optional)
Allow to filter emails according if they have been sent or not.
Example:
Request:
GET to http://0.0.0.0:3000/emails/?limit=10
Response:
[
{
"created_at": "2019-02-03 20:48:44.573069",
"from_address": "[email protected]",
"html_message": null,
"id": 1,
"retries": 1,
"sent": true,
"sent_at": "2019-02-03 20:48:53.534887",
"subject": "Test 1",
"text_message": "Just testing the sender app",
"to_address": "[email protected]"
},
{
"created_at": "2019-02-03 21:07:04.140945",
"from_address": "[email protected]",
"html_message": null,
"id": 2,
"retries": 1,
"sent": true,
"sent_at": "",
"subject": "Test 2",
"text_message": "Another example",
"to_address": "[email protected]"
}
]
GET to http://0.0.0.0:3000/emails/
Returns a list of all created e-mails.
Example:
Example:
Request:
GET to http://0.0.0.0:3000/emails/1/
Response:
{
"created_at": "2019-02-03 20:48:44.573069",
"from_address": "[email protected]",
"html_message": null,
"id": 1,
"retries": 1,
"sent": true,
"sent_at": "2019-02-03 20:48:53.534887",
"subject": "Test 1",
"text_message": "Just testing the sender app",
"to_address": "[email protected]"
}
POST to http://0.0.0.0:3000/emails/
URL parameters:
autosend: true|false (optional)
Determines if email should be sent in the same moment or not.
Body (json):
It should include: subject
, text_message
.
It can, optionally, include: to_address
, subject
, text_message
, html_message
.
Headers:
"Content-type": "application/json"
Example:
Request:
POST to http://0.0.0.0:3000/emails/
Body:
{
"subject": "Hi!",
"text_message": "This is my first e-mail using sender webservice!"
}
Response:
{
"id": 3,
"sent": true
}
You can send an email passing true
to autosend
parameter when creating it.
If you need to send an email which is already created, you should:
POST to http://0.0.0.0:3000/emails/<int:email_id>/send
Example:
Request:
POST to http://0.0.0.0:3000/emails/1/send
Response:
{
"id": 1,
"sent": true
}
To build the test image:
make build-test
To run tests:
make test