Skip to content

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:

NameTypeDescription
recipient

Required

StringThe email recipient. It could be a single value or an array of values when using recipients instead.
recipients

Optional

ArrayAn array of recipients, required if recipient is not provided. [Learn more on multiple recipients](/docs/sending-mails/recipient#multiple-recipients).
subject

Required

StringThe subject of the email.
template

Required

StringThe slug of the template to be used.
sender

Optional

String|ObjectThe 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

ObjectA key-value object of variables to render the template. [Learn more on variables](/docs/sending-mails/variables).
enqueue

Optional

BooleanChoose if sending the email in a background queue; might need a [little setup to work](/docs/sending-mails/queue). **Default**: false.
trigger

Optional

StringThe trigger name, useful to identify emails coming from multiple sources/applications.
cc

Optional

StringRecipient to put in copy for the current email.
bcc

Optional

StringRecipient to put in hidden copy for the current email.
attachments

Optional

ArrayThe files to be attached to the email.
remoteAttachments

Optional

ArrayList of remote resources to be attached to the email. [Learn more on remote attachments](/docs/sending-mails/attachments#remote-attachments).
tags

Optional

ArrayList of tags to be sent to SMTP provider.
metadata

Optional

ObjectObject 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"
}