Sending email

Batches

Send up to 100 different emails in one request.

POST/emails/batch takes a list of up to 100 emails, each with the fields of POST/emails, and sends each as its own email: its own id, status, events and stats. It answers 200 with one result per email, in the same order: its id, or the error that refused it. One invalid email never fails the others.

A batch
curl -X POST https://yousendit.io/api/v1/emails/batch \
  -H "Authorization: Bearer $YOUSENDIT_API_KEY" \
  -H "Content-Type: application/json" \
  -d '[
    { "from": "Acme <hello@acme.com>", "to": "sam@example.com", "subject": "Your receipt", "html": "<p>Thanks, Sam!</p>" },
    { "from": "Acme <hello@acme.com>", "to": "alex@example.com", "subject": "Your receipt", "html": "<p>Thanks, Alex!</p>" }
  ]'
Batch response
{ "data": [
  { "index": 0, "id": "…", "status": "queued", "scheduled_at": null, "error": null },
  { "index": 1, "id": null, "status": null, "scheduled_at": null,
    "error": { "code": "domain_not_verified", "message": "…", "param": "1.from" } }
] }

An error's param starts with the email's position in the list. The request as a whole (not a list, an empty one, more than 100) is refused with 400. Batches carry no attachments: send those one by one through POST/emails. To send the same template to many people with different values, give each email its own variables.

For per-person stats, give each email in the batch one recipient. An email with several addresses in to is one message: delivery and bounces are known per address, but an open or a click cannot be told apart between its recipients.