Giter Club home page Giter Club logo

rampup2020's Introduction

Endava's RampUp 2020-1: Mail2Clients

Build Status

This web application allows the user to send emails by using JAVA 1.8 REST services.

Software requirements

This application uses a Tomcat server that runs .war artifact, an SMTP server to send the emails and a Postgres database where the emails sent are stored. Also, the artifact is built with Maven.

For this case, you will need:

  • Docker

  • Docker-compose

Usage

Deploy

For deploy, the variables POSTGRES_USER, POSTGRES_PASSWORD, GMAIL_USER, and GMAIL_PASSWORD must be set.

export POSTGRES_USER=admin_db
export POSTGRES_PASSWORD=<password of your choice>
export GMAIL_USER=<your Gmail username>
export GMAIL_PASSWORD=<your Gmail password>
docker-compose up --build

NOTE: You must enable less secure apps to access Gmail with this Tutorial.

Test

In these examples, It is recommended to use the Python 3 with the requests module to access the endpoints.

Initial service test

After Tomcat has properly deployed the app you can test the service status calling this endpoint.

http://localhost:8080/test

If it was deployed correctly the output should be like this:

Mail2CLients - Rest Service - Test Succeeded! 

Send an email

Once all the services required are running, you can test the web app by accessing:

POST rest service
    http://localhost:8080/v1/emails

Parameters
    "subject" Subject of the email, it will be used on email inbox. Example: Hello I'm here!
    "content" Text content, please do not add javascript in this filed, mailbox validate javascript content and they will reject the email. 
    "recipients" List of email addresses to send the email, if they are more that one separate them with ';'. Example: [email protected]; [email protected];.

Python script to access to the endpoint:

from requests import get, post

r = post("http://localhost:8080/v1/emails", data={'subject': 'Test', 'content': 'This is a test', 'recipients': '[email protected]'})
print(r.text[:700] + '...')

If the request was processed correctly the output should be like this:

{
  "code": 202,
  "status": "ACCEPTED",
  "url": "[POST] http://localhost:8080/v1/emails?subject=Subject%20test&content=Testing%20content%20on%20email&[email protected];",
  "message": "Email task was accepted and sent to SMTP",
  "data": {
    "serial": 1491218659389,
    "from": "127.0.0.1",
    "mailsList": "[email protected];",
    "subject": "Subject test",
    "content": "Testing content on email",
    "warnings": null,
    "malformedDirectEmails": null
  }
} 

List of emails logged

Another REST service includes in the JAVA app is the list of all delivered emails.

GET rest service
    http://localhost:8080/v1/logger?startDate=&endDate=2017-12-01 00:00&onlyDelivered=false

Parameters
    "startDate" Initial date to search. Example: 2017-01-01 00:00
    "endDate" Final date to search. Example: 2017-12-01 00:00
    "onlyDelivered" It will filter the results by only delivered emails. Example: false *To return all emails on log.

Python script to access to the endpoint:

from requests import get, post

r = get("http://localhost:8080/v1/logger?startDate=2020-01-01%2000:00&endDate=2021-01-01%2000:00&onlyDelivered=false")
print(r.text[:700] + '...')

This is the expected output:

{
  "code": 200,
  "status": "OK",
  "url": "[GET] http://localhost:8080/v1/logger?startDate=2017-01-01%2000:00&endDate=2017-12-01%2000:00&onlyDelivered=false",
  "message": "Mail2Clients request response.",
  "data": [
    {
      "serial": "1491359400489",
      "subject": "Hello Mail2Clients",
      "delivered": true,
      "content": "Working as a charm!",
      "versionDate": "04/03/2017 05:08:51"
    }
  ]
}

List of emails logged by Serial or Subject

Search REST services included: By Serial or Subject. Filter by subject will return all the emails that contain the keywords sent.

GET rest services
    http://localhost:8080/v1/logger/suject/Docker Test
    http://localhost:8080/v1/logger/serial/1491359396709

Parameters
    "subject" Text to filter by. Example: Docker Test
    "serial" Generated id to filter by. Example: 1491359396709

Python script to access to the endpoint:

from requests import get, post

r = get("http://localhost:8080/v1/logger/subject/Docker%20Test")
print(r.text[:700] + '...')

s = get("http://localhost:8080/v1/logger/serial/1491359396709")
print(s.text[:700] + '...')

This is the expected output:

{
  "code": 200,
  "status": "OK",
  "url": "[GET] http://localhost:8080/v1/logger/subject/Docker%20Test",
  "message": "Mail2Clients request response.",
  "data": [
    {
      "serial": "1491359396709",
      "subject": "Docker Test",
      "delivered": true,
      "content": "Email build and send to SMTP",
      "versionDate": "04/05/2017 02:29:56"
    },
    {
      "serial": "1491359400486",
      "subject": "Docker Test 1",
      "delivered": true,
      "content": "Email build and send to SMTP",
      "versionDate": "04/05/2017 02:30:00"
    },
    {
      "serial": "1491359403198",
      "subject": "Docker Test 2",
      "delivered": true,
      "content": "Email build and send to SMTP",
      "versionDate": "04/05/2017 02:30:03"
    }
  ]
}

rampup2020's People

Contributors

twogg-git avatar mnl359 avatar zelfick avatar

Stargazers

Sergio Andres Rojas Muñoz avatar

Watchers

James Cloos avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.