Centralised template repository that receives a HTTP POST with json data, applies a template and emails it.
-
Add a new handlebars template to
/templates/
We will use test.hbs for the example. -
Add the needed credentials to the different environments in
/config/
-
Start the application selecting the port you want to listen.
node index.js 8000
- Send a HTTP POST request with the dynamic data of the template in json format and the destination address.
curl localhost:8000 \
--header "x-template: test.hbs" \
--header "x-to: [email protected]" \
-d '{"name" : "John Doe"}'
- You will get back a 200 response with a success message or a 500 in case any configuration fails.
{ "response" : "mail sent" }
- The mail address receives the email with the selected template
Hello, my name is John Doe.
You can also define shorthands in the /presets/
folder for widely used configurations
{
"template": "registrationEmail.hbs",
"from": "[email protected]",
"subject": "Please confirm your signup",
"to": "[email protected]"
}
This presets file can be selected by sending the x-presets
header.
Additional headers like x-to
or x-subject
will override the preset configuration.
The templates use handlebars and they are compiled and cached on the application startup to optimise runtime performance.
The mails are sent using nodemailer library using a stmp pool. Environment files in /config/
define the transport and pool size.
-Improve testing coverage.
-Define load tests.
-Add authentication capabilities.
-Accept gzip requests.