Sending email

Templates

Design an email in the app and send it from your code, filled in with your values.

Design an email once in the app (Templates → Transactional, with the drag-and-drop builder) and send it with your own values. Instead of html / text, give template_id and variables. subject is optional: leave it out to use the template's subject, filled in with the same variables.

Send a template with curl
curl -X POST https://yousendit.io/api/v1/emails \
  -H "Authorization: Bearer $YOUSENDIT_API_KEY" \
  -H "Content-Type: application/json" \
  -d '{
    "from": "Acme <orders@acme.com>",
    "to": "sam@example.com",
    "template_id": "<template id>",
    "variables": {
      "name": "Sam",
      "order": { "number": 1042, "total": "59.00" },
      "items": [{ "name": "Mug", "price": "12.00" }, { "name": "Tea", "price": "47.00" }]
    }
  }'
Only transactional templates can be sent this way. A marketing template (made for campaigns and flows) is refused with template_not_transactional. GET/templates lists your transactional templates with the variable names each one uses.

Variables

{{ name }} reads variables.name and {{ order.total }} reads variables.order.total. Filters ({{ name | default: 'there' }}, money, date, upcase …), {% if %} and {% for item in items %} work as in campaigns. There is no contact here: a tag your variables do not name, such as {{ first_name }}, comes out empty. Values are escaped for where they land (a link must be http, https, mailto, tel or sms), so a value can never add HTML. No unsubscribe footer is added.

When it is filled in

The email is filled in when it is accepted, and what was sent is what is stored; the email object says which template it used (template_id). A template that cannot be sent as it is, or that would be too large with your values, is refused with a 422 and nothing is sent. Limits for variables: 5 levels, 2,000 keys and values in all, names up to 100 characters, text values up to 5,000 characters and 200,000 together. A batch may use up to 10 different templates.