API Endpoint
To start sending emails, after you created a template, you should invoke the POST /api/send
endpoint, for example:
shell
curl -XPOST \
-H 'Authorization: Bearer xxxxx' \
-H "Content-type: application/json" \
-d '{"recipient":"foo@example.org","subject":"My first email","template":"welcome"}' \
http://localhost:8000/api/send
That's it. There are a few other available fields too:
Name | Type | Description |
---|---|---|
recipient Required | String | The email recipient. It could be a single value or an array of values when using recipients instead. |
recipients Optional | Array | An array of recipients, required if recipient is not provided. [Learn more on multiple recipients](/docs/sending-mails/recipient#multiple-recipients). |
subject Required | String | The subject of the email. |
template Required | String | The slug of the template to be used. |
sender Optional | String|Object | The sender of the current email. If empty, it will be taken from the app settings. [Learn more on settings](/docs/sending-mails/api-endpoint#sender). |
variables Optional | Object | A key-value object of variables to render the template. [Learn more on variables](/docs/sending-mails/variables). |
enqueue Optional | Boolean | Choose if sending the email in a background queue; might need a [little setup to work](/docs/sending-mails/queue). **Default**: false. |
trigger Optional | String | The trigger name, useful to identify emails coming from multiple sources/applications. |
cc Optional | String | Recipient to put in copy for the current email. |
bcc Optional | String | Recipient to put in hidden copy for the current email. |
attachments Optional | Array | The files to be attached to the email. |
remoteAttachments Optional | Array | List of remote resources to be attached to the email. [Learn more on remote attachments](/docs/sending-mails/attachments#remote-attachments). |
tags Optional | Array | List of tags to be sent to SMTP provider. |
metadata Optional | Object | Object of key => value of metadata to be sent to SMTP provider. |
Sender
By default MailCarrier will use, as sender, the values defined by your environment variables MAIL_FROM_ADDRESS
and MAIL_FROM_NAME
(which can be empty).
You can override these values at runtime when making an API call by defining the sender
property:
json
{
// Other variables
"sender": "sender@example.org"
}
Or, specifying the name too:
json
{
// Other variables
"sender": {
"email": "sender@example.org",
"name": "Sender name"
}
}
Cc & Bcc
You can specify a cc or bcc by providing their relative keys to your payload:
json
{
// Other variables
"cc": "cc@example.org",
"bcc": "bcc@example.org"
}