# README
#+title: mailer
Simple transactional mailer middleware. Listens for POST HTTP requests using webserver, sends emails using provider API upon request.
To send an email you need to send POST request to =/send= endpoint with data being form-encoded (header =application/x-www-form-urlencoded=).
- Features
-
Multiple transactional mail providers
- Mandrill
- Mailgun
- SpartPost
- TODO: SendGrid
-
[[http://mjml.io][MJML]] templates support (if =mjml= app is available)
-
Simplest API possible
-
Async send
- Authentication Authentication is done via tokens, configured in configuration file. Token should be sent in HTTP Header:
#+begin_example Authorization: #+end_example
- Data Data is provided as JSON document of the following format:
#+begin_example json { "subject": "Hello message", "text": "Hello, world!", "html": "
Hello, world!
", "mjml": "Some mjml markup", "from": { "name": "pavel", "address": "[email protected]" }, "to": [ { "name": "pavel", "address": "[email protected]" } ], "cc": [ { "name": "pavel", "address": "[email protected]" } ], "bcc": [ { "name": "pavel", "address": "[email protected]" } ] } #+end_example/Note/, that if =html= parameter is provided, then =mjml= parameter is ignored. If both =text= and =html= (or =mjml=) parameters are provided then resulting email will have both html and text parts (what part will be visible by user depends on user mail client software).
- Return codes Application returns result in JSON encoded format.
Structure of response:
#+begin_example {"Status": "", "Message": ""} #+end_example
- =Status= - can be either =ok=, or =error=. If =error= then corresponding non-200 HTTP return code will be returned
- =Message= - string, explaining status message
- Requirements
- Go runtime
- [[http://mjml.io][MJML]] when using mjml templates
- Example
-
Configure =config.toml= file and set up transactional mail provider. See =config-example.toml= for example.
-
Run it via docker:
docker run -d --name mailer -p 1233:1233 -v /path/to/config/toml:/config.toml velppa/go-mailer
-
Send test email
#+begin_src sh
curl -X POST -H "Authorization: token"
-H "Content-Type: application/json"
-H "Cache-Control: no-cache"
-d '{
"subject": "Hello from Mailer app",
"text": "Hello, world!",
"html": "",
"from": {"name": "Mailer App", "address": "[email protected]"},
"to": [{"name": "recipient", "address": "[email protected]"}]
}'
"http://your.domain.com:1233/send"
#+end_src