`lumail@2.1.0` · [`lumail.emails`](/docs/sdk/v2/emails)

```typescript
emails.batch(emails: SendEmailParams[], options?: { idempotencyKey?: string }): Promise<LumailResult<{ data: { id: string }[] }>>
```

Up to 100 sends. Each item matches [`emails.send`](/docs/sdk/v2/emails-send). HTTP body is the JSON array.

## Body Parameters

| Name | Type | Description |
| -------- | ------------------- | ---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
| `emails` | `SendEmailParams[]` | **Required.** First argument. Array of send payloads. Max 100. Each item: `from`, `to`, `subject`, and exactly one of `html`, `tiptap`, or `markdown`. Also accepts `text`, `reply_to`, `cc`, `bcc`, `headers`, `tags`, `preview`. |

## Options

| Name | Type | Description |
| ---------------- | ------ | ------------------------------------------------------------------------------------------------------ |
| `idempotencyKey` | string | Second-argument option. Mapped to the `Idempotency-Key` header. The server suffixes `:index` per item. |

## Response Fields

| Field | Type | Description |
| ------ | ------------------ | -------------------------------------------- |
| `data` | `{ id: string }[]` | Queued email ids, same order as the request. |

`data` is `{ data: [{ id }] }`. Failures return `{ data: null, error: { name, message, statusCode } }`.


## API Reference
**Method:** POST
**Endpoint:** /api/v2/emails/batch

### SDK
```ts
import { Lumail } from "lumail";

const lumail = new Lumail({ apiKey: process.env.LUMAIL_API_KEY });
const { data, error } = await lumail.emails.batch(
  [
    { from: "hello@yourdomain.com", to: "a@example.com", subject: "A", html: "<p>A</p>" },
    { from: "hello@yourdomain.com", to: "b@example.com", subject: "B", html: "<p>B</p>" },
  ],
  { idempotencyKey: "welcome-batch-1" },
);
if (error) {
  throw error;
}
console.log(data.data.map((email) => email.id));
```

### cURL
```bash
curl -X POST https://lumail.io/api/v2/emails/batch \
  -H "Authorization: Bearer YOUR_API_TOKEN" \
  -H "Content-Type: application/json" \
  -H "Idempotency-Key: welcome-batch-1" \
  -d '[
    {"from":"hello@yourdomain.com","to":"a@example.com","subject":"A","html":"<p>A</p>"},
    {"from":"hello@yourdomain.com","to":"b@example.com","subject":"B","html":"<p>B</p>"}
  ]'
```

### JavaScript
```javascript
const response = await fetch("https://lumail.io/api/v2/emails/batch", {
  method: "POST",
  headers: {
    Authorization: "Bearer YOUR_API_TOKEN",
    "Content-Type": "application/json",
    "Idempotency-Key": "welcome-batch-1",
  },
  body: JSON.stringify([
    { from: "hello@yourdomain.com", to: "a@example.com", subject: "A", html: "<p>A</p>" },
    { from: "hello@yourdomain.com", to: "b@example.com", subject: "B", html: "<p>B</p>" },
  ]),
});
const data = await response.json();
```

### Success Response
```json
{ "data": [{ "id": "eml_..." }, { "id": "eml_..." }] }
```

### Error Response
```json
{
  "name": "validation_error",
  "message": "Batch payload must be an array of emails",
  "statusCode": 422
}
```
