Transactional emails
On this page:
Using /api/transactional-mails/send
endpoint, you can send a transactional email.
$ MAILCOACH_TOKEN="your API token" $ curl -X POST https://<your-mailcoach-domain>/api/transactional-mails/send \ -H "Authorization: Bearer $MAILCOACH_TOKEN" \ -H 'Accept: application/json' \ -H 'Content-Type: application/json' \ -d '{"mail_name":"name-of-the-mail", "subject": "Subject of your email", ...}'
These are the parameters you should give to this call:
-
mail_name
: the name of the transactional email as specified on the email’s screen. This is required if you don’t sendhtml
. -
html
: if you want to use a transactional email (as defined on the email screen), you can provide HTML that will be used as the body of your email. -
subject
: the subject used for the transactional email -
from
: the from address that will be used. -
to
: the to address to use. You can specify multiple addresses comma-delimited. -
cc
: the cc address to use. You can specify multiple addresses comma-delimited. -
bcc
: the bcc address to use. You can specify multiple addresses comma-delimited. -
store
: defaults totrue
; when set to false, the transactional email will not be added to the transactional email log. -
mailer
: the name of the mailer to use to send the email. If not set, we’ll use the default of your account. -
replacements
: a key-value array that will be used to fill all replacers in your mail. These will only be used if you also specifyname
. -
fake
: a boolean that determines if Mailcoach should actually send the email or just log it in the interface. This way you can use Mailcoach as a Mailtrap or Mailhog replacement
Get all transactional email templates
The /api/transactional-mails/templates
endpoint lists all your transactional emails.
$ MAILCOACH_TOKEN="your API token" $ curl https://<your-mailcoach-domain>/api/transactional-mails/templates \ -H "Authorization: Bearer $MAILCOACH_TOKEN" \ -H 'Accept: application/json' \ -H 'Content-Type: application/json'
Searching for a specific template by its name is possible on this endpoint using ?filter[name]=searchterm
. Replace searchterm
with the name of your template.
Sorting is possible on this endpoint on created_at
. For example ?sort=-created_at
to sort descending on created_at
.
As a result, you get the details of all your templates:
{ "data": [ { "uuid": "2ca0e737-b907-468f-819f-5d16e6bd6852", "name": "alias", "to": null, "cc": null, "bcc": null, "subject": "A subject", "html": "", "store_mail": true, "created_at": "2020-08-06T12:11:26.000000Z", }, { "uuid": "a69075c6-ff5c-4b6a-b217-12026cb72e4f", "name": "consectetur", "to": null, "cc": null, "bcc": null, "subject": "A subject", "html": "", "store_mail": true, "created_at": "2020-08-06T12:11:26.000000Z", }, { "uuid": "11ce123b-57c4-429b-9840-c79f8047d8aa", "name": "velit", "to": null, "cc": null, "bcc": null, "subject": "A subject", "html": "", "store_mail": true, "created_at": "2020-08-06T12:11:26.000000Z", } ], "links": { "first": "https://<your-mailcoach-domain>/api/transactional-mails/templates?page=1", "last": "https://<your-mailcoach-domain>/api/transactional-mails/templates?page=1", "prev": null, "next": null }, "meta": { "current_page": 1, "from": 1, "last_page": 1, "path": "https://<your-mailcoach-domain>/api/transactional-mails/templates", "per_page": 15, "to": 3, "total": 3 } }
Get a specific transactional email
If you don’t want to retrieve all templates, you can get a specific template if you know its UUID. The example below will get the details of the template with UUID 11ce123b-57c4-429b-9840-c79f8047d8aa
.
$ MAILCOACH_TOKEN="your API token" $ curl https://<your-mailcoach-domain>/api/transactional-mails/templates/11ce123b-57c4-429b-9840-c79f8047d8aa \ -H "Authorization: Bearer $MAILCOACH_TOKEN" \ -H 'Accept: application/json' \ -H 'Content-Type: application/json'
Response:
{ "data": { "uuid": "2ca0e737-b907-468f-819f-5d16e6bd6852", "name": "alias", "to": null, "cc": null, "bcc": null, "subject": "A subject", "html": "", "store_mail": true, "created_at": "2020-08-06T12:11:26.000000Z", } }