# Send up to 500 different messages in one request

`POST /mail/send/batch` · Rivier · campaigns

Send up to 500 different messages in one request. Each item is accepted or rejected on its own; the answer has one result per item and a batchId that cancels the whole batch while it waits.

- Scope: campaigns:write
- Mcp: rivier_campaign_mail_send_batch
- Graphql: Mutation.campaignsMailBatchSendCreate
- Sdk: mail.sendBatch
- Cli: mail send-batch

## Request body

`application/json`

```json
{
  "type": "object",
  "properties": {
    "messages": {
      "type": "array",
      "items": {
        "type": "object",
        "properties": {
          "to": {
            "type": "string",
            "minLength": 3,
            "maxLength": 320
          },
          "from": {
            "type": "string",
            "minLength": 3,
            "maxLength": 320,
            "description": "Defaults to the project's sending address; must be on its sending domain"
          },
          "fromName": {
            "type": "string",
            "maxLength": 120
          },
          "replyTo": {
            "type": "string",
            "minLength": 3,
            "maxLength": 320
          },
          "subject": {
            "type": "string",
            "maxLength": 998,
            "description": "Required unless the template has one. May use {{variables}}"
          },
          "html": {
            "type": "string",
            "maxLength": 1000000
          },
          "text": {
            "type": "string",
            "maxLength": 1000000,
            "description": "Defaults to the html as plain text"
          },
          "template": {
            "type": "string",
            "maxLength": 120,
            "description": "A template name or id from the template library"
          },
          "data": {
            "type": "object",
            "additionalProperties": {},
            "description": "Values the template or the message reads: {{name}}, {{#if plan == \"pro\"}}, {{#each items}}"
          },
          "group": {
            "type": "string",
            "maxLength": 40,
            "description": "Unsubscribe group; adds the unsubscribe link and one-click header, and honours the person's choice"
          },
          "tags": {
            "type": "array",
            "items": {
              "type": "string",
              "maxLength": 40
            },
            "maxItems": 10
          },
          "headers": {
            "type": "object",
            "additionalProperties": {
              "type": "string",
              "maxLength": 998
            },
            "description": "Extra headers (X-...); headers the platform sets are refused"
          },
          "sendAt": {
            "type": "string",
            "maxLength": 40,
            "description": "ISO 8601 time, at most 30 days ahead; default now"
          },
          "trackOpens": {
            "type": "boolean"
          },
          "trackClicks": {
            "type": "boolean"
          },
          "attachments": {
            "type": "array",
            "items": {
              "type": "object",
              "properties": {
                "filename": {
                  "type": "string",
                  "minLength": 1,
                  "maxLength": 200,
                  "description": "The name the recipient sees, such as invite.ics"
                },
                "contentType": {
                  "type": "string",
                  "maxLength": 120,
                  "description": "Defaults from the file name; text/calendar for an invitation"
                },
                "content": {
                  "type": "string",
                  "minLength": 1,
                  "maxLength": 7000000,
                  "description": "The file's bytes in base64"
                }
              },
              "required": [
                "filename",
                "content"
              ],
              "additionalProperties": false
            },
            "maxItems": 10,
            "description": "Up to 10 files, 5 MB together; programs and scripts are refused"
          }
        },
        "required": [
          "to"
        ],
        "additionalProperties": false
      },
      "minItems": 1,
      "maxItems": 500
    },
    "sandbox": {
      "type": "boolean"
    },
    "idempotencyKey": {
      "type": "string",
      "minLength": 1,
      "maxLength": 200
    }
  },
  "required": [
    "messages"
  ],
  "additionalProperties": false
}
```

## Responses

- `202`: Success
- `400`: The request was malformed
- `401`: No valid credential
- `403`: The credential lacks the scope, origin or address
- `429`: Over the key's rate limit; see Retry-After

## Example

```sh
curl -X POST 'https://api.rivier.ai/mail/send/batch' \
  -H 'Authorization: Bearer $KEY' \
  -H 'Content-Type: application/json' \
  -d '{
  "messages": [
    {
      "to": "string"
    }
  ]
}'
```
