REST API

The Mailer API is used by other applications to send emails. There is only one endpoint, which is used to send emails.

POST /api/mail

This endpoint is used to send mail. There are no HTTP headers required, but the request must use the POST HTTP method, and it must have a JSON request body. There are a couple of different ways to use this endpoint.

Using Pre-Rendered HTML/Text

To send an email using your own HTML and/or text content, use the html_body and/or text_body fields:

{
	"access_key": "004fe73d24eeab2cbdbc286f828ae85010a656db0428c9fefb6998a741f1c7d477ca15875b797a782051f1fbfa8ed99c16751377d187ddb4438ac6afe2204c79",
	"recipients": [ "user1@example.com" ],
	"cc": [],
	"bcc": [],
	"reply_to": "",
	"subject": "Email from Mailer",
	"html_body": "<h1>This is HTML</h1>",
	"text_body": "This is text."
	
}

Using a Template

To send an email using a template defined in Mailer, pass the template name and some (optional) context data in place of the html_body and text_body fields:

{
	"access_key": "004fe73d24eeab2cbdbc286f828ae85010a656db0428c9fefb6998a741f1c7d477ca15875b797a782051f1fbfa8ed99c16751377d187ddb4438ac6afe2204c79",
	"recipients": [ "user1@example.com" ],
	"cc": [],
	"bcc": [],
	"reply_to": "",
	"subject": "Email from Mailer",
	"template": "welcome",
	"context": {
		"name": "Test User"
	}
}

The context data can be any valid JSON data (string, number, object, array, etc.), and will be passed into the template rendering engine. In the example above, where the context data is an object with one property (name), you might have a text template of:

Welcome, {{ .name }}!

and an HTML template of:

<h1>Welcome, {{ .name }}!</h1>