Microservice which provides API for sending emails. Application is written in Swift and Vapor 4.
Service provides simple RESTful API. Below there is a description of each endpoint.
Endpoint for sending emails.
Request
METHOD: POST
URL: /emails/send
BODY:
{
    "to: {
        "address": "[email protected]",
        "name": "John Doe"
    },
    "subject": "Email subject",
    "body": "Email content",
    "from": {
        "address": "[email protected]",
        "name": "Emily Doe"
    },
    "replyTo": {
        "address": "[email protected]",
        "name": "Viki Doe"
    }
}
Response
STATUS: 200 (Ok)
BODY:
{
    "result": true
}
Errors
STATUS: 400 (BadRequest)
BODY: 
{
    "error": true,
    "code": "validationError",
    "reason": "Validation errors occurs.",
    "failures": [
        {
            "field": "[FIELD]",
            "failure": "[VALIDATION MESSAGE]"
        }
    ]
}
First you need to have Swift installed on your computer. Next you should run following commands:
$ git clone https://github.com/Mikroservices/Emails.git
$ cd Emails
$ swift package update
$ swift buildNow you can run the application:
$ .build/debug/Run serve --port 8000If application starts open following link in your browser: http://localhost:8000. You should see blank page with text: Service is up and running!. Now you can use API which is described above.
You can define application settings in appsettings.json file or by setting suitable environment variables:
- smtp.fromName
- smtp.fromEmail
- smtp.hostname
- smtp.port
- smtp.username
- smtp.password
- smtp.secure
You can deploy application as service in the Kubernates cluster or as a single service in Linux.
You must modify and copy file users.service to your Linux server (folder /lib/systemd/system). Then you can start service using below command:
$ systemctl start users.serviceIf you want start service at system boot you must run following command:
$ systemctl enable users.service