Skip to content

noviluni/sender

Repository files navigation

Sender

Email sender microservice

This is a proof of concept. A RESTful microservice to send e-mails using smtp credentials.

Configuration

Credentials

It's necessary to create the .env file:

cp .env.template .env

And fill DEFAULT_TO_ADDRESS, FROM_ADDRESS and EMAIL_PASSWORD variables.

To build the image:

make build

To run the webserver:

make up

Using

To list all created emails:

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]"
  }
]

To see the detail of a created email:

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]"
  }

To create an email:

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
  }

To send an email:

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
  }

Testing

To build the test image:

make build-test

To run tests:

make test

About

Email sender microservice

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published