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/sendThat's it. There are a few other available fields too:
| Name | Type | Description |
|---|---|---|
recipientRequired | String | The email recipient. It could be a single value or an array of values when using recipients instead. |
recipientsOptional | Array | An array of recipients, required if recipient is not provided. [Learn more on multiple recipients](/docs/sending-mails/recipient#multiple-recipients). |
subjectRequired | String | The subject of the email. |
templateRequired | String | The slug of the template to be used. |
senderOptional | 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). |
variablesOptional | Object | A key-value object of variables to render the template. [Learn more on variables](/docs/sending-mails/variables). |
enqueueOptional | Boolean | Choose if sending the email in a background queue; might need a [little setup to work](/docs/sending-mails/queue). **Default**: false. |
triggerOptional | String | The trigger name, useful to identify emails coming from multiple sources/applications. |
ccOptional | String | Recipient to put in copy for the current email. |
bccOptional | String | Recipient to put in hidden copy for the current email. |
attachmentsOptional | Array | The files to be attached to the email. |
remoteAttachmentsOptional | Array | List of remote resources to be attached to the email. [Learn more on remote attachments](/docs/sending-mails/attachments#remote-attachments). |
tagsOptional | Array | List of tags to be sent to SMTP provider. |
metadataOptional | 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"
}