# Send many messages at once

Pass an array to `send` and Mailset takes up to 100 messages in one call. Each gets its own result, in order, and a refused message never stops the rest. A longer array is fine, since the SDK splits it into calls of 100 for you.

Over HTTP it's `messages.submitMany`, with each message as raw MIME.

## Send

```typescript
const results = await mailset.send(
	receipts.map((receipt) => ({
		from: 'Acme <hello@example.com>',
		to: receipt.email,
		subject: `Your receipt for ${receipt.id}`,
		text: receipt.text,
		idempotencyKey: `receipt-${receipt.id}`,
	})),
);
```

```python
def receipt_mail(receipt: Dict[str, str]) -> SendInput:
    return {
        "from": "Acme <hello@example.com>",
        "to": receipt["email"],
        "subject": f"Your receipt for {receipt['id']}",
        "text": receipt["text"],
        "idempotency_key": f"receipt-{receipt['id']}",
    }


messages = [receipt_mail(r) for r in receipts]
results = mailset.send(messages)
```

```go
import (
	"context"
	"fmt"
	"log"

	mailset "mailset.app/go"
)

var messages []mailset.Message
for _, receipt := range receipts {
	messages = append(messages, mailset.Message{
		From:           "Acme <hello@example.com>",
		To:             []string{receipt.Email},
		Subject:        "Your receipt for " + receipt.ID,
		Text:           receipt.Text,
		IdempotencyKey: "receipt-" + receipt.ID,
	})
}
results, err := client.SendMany(ctx, messages)
if err != nil {
	log.Fatal(err)
}
```

```ruby
results = mailset.send_emails(
  receipts.map do |receipt|
    {
      from: 'Acme <hello@example.com>',
      to: receipt[:email],
      subject: "Your receipt for #{receipt[:id]}",
      text: receipt[:text],
      idempotency_key: "receipt-#{receipt[:id]}"
    }
  end
)
```

```php
$messages = [];
foreach ($receipts as $receipt) {
    $messages[] = [
        'from' => 'Acme <hello@example.com>',
        'to' => $receipt['email'],
        'subject' => "Your receipt for {$receipt['id']}",
        'text' => $receipt['text'],
        'idempotencyKey' => "receipt-{$receipt['id']}",
    ];
}
$results = $mailset->sendMany($messages);
```

```java
List<Message> messages = new ArrayList<>();
for (Receipt receipt : receipts) {
    messages.add(Message.builder()
            .from("Acme <hello@example.com>")
            .to(receipt.email())
            .subject("Your receipt for " + receipt.id())
            .text(receipt.text())
            .idempotencyKey("receipt-" + receipt.id())
            .build());
}
List<SendResult> results = mailset.send(messages);
```

```rust
let messages = receipts.iter().map(|receipt| {
    Message::builder()
        .from("Acme <hello@example.com>")
        .to(receipt.email)
        .subject(format!(
            "Your receipt for {}",
            receipt.id
        ))
        .text(receipt.text)
        .idempotency_key(format!(
            "receipt-{}",
            receipt.id
        ))
});
let results = mailset.send_many(messages).await?;
```

## Read the answer

You get one result per message, in the order you sent them.

```typescript
for (const [index, result] of results.entries()) {
	const id = receipts[index]?.id;
	if (result.ok) console.log(result.status, result.id);
	else {
		const { code, message } = result.error;
		console.error(id, code, message);
	}
}
```

```python
for receipt, result in zip(receipts, results):
    if result["ok"]:
        print(result["status"], result["id"])
    else:
        error = result["error"]
        print(receipt["id"], error.code, error.message)
```

```go
import (
	"context"
	"fmt"
	"log"

	mailset "mailset.app/go"
)

for i, result := range results {
	id := receipts[i].ID
	if result.OK {
		fmt.Println(result.Status, result.ID)
		continue
	}
	refused := result.Error
	log.Println(id, refused.Code, refused.Message)
}
```

```ruby
results.each_with_index do |result, index|
  id = receipts[index][:id]
  if result.ok?
    puts "#{result.status} #{result.id}"
  else
    error = result.error
    warn "#{id} #{error.code} #{error.message}"
  end
end
```

```php
foreach ($results as $index => $result) {
    $id = $receipts[$index]['id'];
    if ($result instanceof Sent) {
        echo "{$result->status} {$result->id}", PHP_EOL;
        continue;
    }
    $code = $result->error->errorCode;
    $message = $result->error->getMessage();
    error_log("{$id} {$code} {$message}");
}
```

```java
for (int i = 0; i < results.size(); i++) {
    String id = receipts.get(i).id();
    SendResult result = results.get(i);
    if (result instanceof Sent sent) {
        System.out.println(
                sent.status() + " " + sent.id());
    } else if (result instanceof NotSent no) {
        MailsetException error = no.error();
        System.err.println(id + " " + error.getCode()
                + " " + error.getMessage());
    }
}
```

```rust
let rows = results.iter().zip(receipts);
for (result, (id, _)) in rows {
    let error = match result {
        Ok(sent) => {
            println!("{:?} {}", sent.status, sent.id);
            continue;
        }
        Err(not) => &not.error,
    };
    let code = error.code();
    eprintln!("{id} {code} {}", error.message());
}
```

## What throws

With an array, the SDK's `send` throws only when nothing was taken: the key was refused, Mailset couldn't be reached, or two messages carry the same idempotency key. Once any message is in, a later failure lands on each message's own result, so you always know which went.

## Without an SDK

`messages.submitMany` takes each whole message as base64. Split a longer list yourself: 100 messages and 48 MB a request.

```http
POST /v1/messages.submitMany
Content-Type: application/json

{
  "input": {
    "messages": [
      {
        "data": "<base64 of message 1>",
        "transactional": true
      },
      {
        "data": "<base64 of message 2>",
        "transactional": true
      }
    ]
  }
}
```

The request answers `200` with `ok: true` even when some messages were refused. Each entry of `data.results` has its own `ok`, with a receipt or an `error`. [Send your own MIME](https://mailset.app/docs/recipes/mime) builds the messages.

## Watch out

- Each message has its own `mode`, `deliverBy` and idempotency key. The same key twice in one batch is refused whole, before anything is sent.
- Your limits apply per message. Past the day's cap, the rest come back `queued` with `sendsAt`: they are taken, and go when there is room.
- This is for your product's email to people who expect it. A newsletter to a list is promotional email, one address a message: see [Honor unsubscribes and complaints](https://mailset.app/docs/recipes/unsubscribes).

---

© 2026 Intenseloop, Inc. Mailset’s site, docs and guides are copyrighted. You may read them and use their code to build with Mailset. Don’t republish them or use them to build a copy of Mailset. Terms: https://mailset.app/terms#content