# Campaigns

Bulk email from a sending domain, and its event hook.

An SDK signs every request with your key: [Authentication](https://mailset.app/docs/authentication.md). To sign one yourself, see [Calling the API without an SDK](https://mailset.app/docs/authentication/http.md).

## campaigns.submit

Queue up to 100 whole messages from a sending domain, each for one recipient.

`POST /v1/campaigns.submit`

A campaigns key for the org. Or a person: an admin or owner of the org.

### Parameters

- `domain` (string, required): The sending domain the messages go from.
- `messages` (array of objects, required): The messages, 1 to 100, each for one recipient. 1 to 100 items.
  - `raw` (string, required): The whole RFC 5322 message, base64, rendered for this one recipient. Up to 1 MB before base64. At most 1,398,110 characters.
  - `campaign` (string, required): Your own id for the campaign: 1 to 64 letters, digits, - or _. It comes back on every event.
  - `recipient` (string, required): Your own id for the recipient, in the same form. It comes back on every event.
  - `track` (object, required): What to track on this message. Only a domain with a tracking domain can track.
    - `opens` (boolean, required): Count when it’s opened.
    - `clicks` (boolean, required): Count clicks on its links.

Beside `input`:

- `org` (string, optional): The org this is about. Needed when the caller is in more than one.

### Returns

`data` is an object with:

- `results` (array of objects): One result per message, in the order they came.
  - `recipient` (string): Your id for the recipient, as given.
  - `id` (string, optional): Mailset’s id for the message. Its events carry it as `message`.
  - `state` (enum, optional): `queued`: it will go. Always `queued`.
  - `refused` (enum, optional): Why it wasn’t taken. `suppressed`: the address bounced or reported spam from this domain before. `invalid`: the message is wrong, or the address can’t or won’t get it. `paused`: the domain is paused or isn’t ready. One of `suppressed`, `invalid`, `paused`.
  - `reason` (string, optional): The refusal, in words.

### Request

TypeScript:

```typescript
import { Mailset } from 'mailset';

// Reads MAILSET_KEY from the environment.
const mailset = new Mailset();

const answer = await mailset.campaigns.submit({
	domain: "news.example.com",
	messages: [
		{
			campaign: "spring-sale",
			recipient: "user_4821",
			track: {
				opens: true,
				clicks: true,
			},
			from: "news@news.example.com",
			to: "maria@example.com",
			subject: "Spring sale",
			text: "Unsubscribe: https://app.example.com/u/4821",
			headers: {
				"List-Unsubscribe":
					"<https://app.example.com/u/4821>",
				"List-Unsubscribe-Post":
					"List-Unsubscribe=One-Click",
			},
		},
	],
});
console.log(answer);
```

Python:

```python
from mailset import Mailset

# Reads MAILSET_KEY from the environment.
mailset = Mailset()

answer = mailset.campaigns.submit(
    {
        "domain": "news.example.com",
        "messages": [
            {
                "campaign": "spring-sale",
                "recipient": "user_4821",
                "track": {"opens": True, "clicks": True},
                "from": "news@news.example.com",
                "to": "maria@example.com",
                "subject": "Spring sale",
                "text": (
                    "Unsubscribe: "
                    "https://app.example.com/u/4821"
                ),
                "headers": {
                    "List-Unsubscribe": (
                        "<https://app.example.com/u/4821>"
                    ),
                    "List-Unsubscribe-Post": (
                        "List-Unsubscribe=One-Click"
                    ),
                },
            },
        ],
    }
)
print(answer)
```

Go:

```go
package main

import (
	"context"
	"fmt"
	"log"

	mailset "mailset.app/go"
)

func main() {
	// Reads MAILSET_KEY from the environment.
	client, err := mailset.NewClient()
	if err != nil {
		log.Fatal(err)
	}
	ctx := context.Background()
	headers := map[string]string{
		"List-Unsubscribe": "<https://app.example.com/" +
			"u/4821>",
		"List-Unsubscribe-Post": "List-Unsubscribe=One-Click",
	}
	message := mailset.CampaignMessage{
		Campaign:  "spring-sale",
		Recipient: "user_4821",
		Track: mailset.CampaignTrack{
			Opens:  true,
			Clicks: true,
		},
		From:    "news@news.example.com",
		To:      []string{"maria@example.com"},
		Subject: "Spring sale",
		Text: "Unsubscribe: " +
			"https://app.example.com/u/4821",
		Headers: headers,
	}
	params := &mailset.CampaignsSubmitParams{
		Domain:   "news.example.com",
		Messages: []mailset.CampaignMessage{message},
	}
	answer, err := client.Campaigns.Submit(ctx, params)
	if err != nil {
		log.Fatal(err)
	}
	fmt.Println(answer)
}
```

Ruby:

```ruby
require 'mailset'

# Reads MAILSET_KEY from the environment: a campaigns key.
mailset = Mailset::Client.new

answer = mailset.campaigns.submit(
  domain: 'news.example.com',
  messages: [
    {
      campaign: 'spring-sale',
      recipient: 'user_4821',
      track: { opens: true, clicks: true },
      from: 'news@news.example.com',
      to: 'maria@example.com',
      subject: 'Spring sale',
      text: 'Unsubscribe: https://app.example.com/u/4821',
      headers: {
        'List-Unsubscribe' =>
          '<https://app.example.com/u/4821>',
        'List-Unsubscribe-Post' =>
          'List-Unsubscribe=One-Click'
      }
    }
  ]
)
p answer
```

PHP:

```php
<?php

require 'vendor/autoload.php';

// Reads MAILSET_KEY from the environment.
$mailset = new Mailset\Client();

$answer = $mailset->campaigns->submit(
    'news.example.com',
    [
        [
            'campaign' => 'spring-sale',
            'recipient' => 'user_4821',
            'track' => [
                'opens' => true,
                'clicks' => true,
            ],
            'from' => 'news@news.example.com',
            'to' => 'maria@example.com',
            'subject' => 'Spring sale',
            'text' =>
                'Unsubscribe: '
                . 'https://app.example.com/u/4821',
            'headers' => [
                'List-Unsubscribe' =>
                    '<https://app.example.com/u/4821>',
                'List-Unsubscribe-Post' =>
                    'List-Unsubscribe=One-Click',
            ],
        ],
    ],
);
echo json_encode($answer, JSON_PRETTY_PRINT), PHP_EOL;
```

Java:

```java
import app.mailset.CampaignMessage;
import app.mailset.Mailset;
import app.mailset.Message;
import app.mailset.model.CampaignSubmitted;
import java.util.List;

// Reads MAILSET_KEY from the environment,
// a campaigns key.
Mailset mailset = Mailset.fromEnv();

var message = Message.builder()
        .from("news@news.example.com")
        .to("maria@example.com")
        .subject("Spring sale")
        .text("Unsubscribe: https://app.example.com/u/482"
                + "1")
        .header("List-Unsubscribe",
                "<https://app.example.com/u/4821>")
        .header("List-Unsubscribe-Post",
                "List-Unsubscribe=One-Click")
        .build();
var campaign = CampaignMessage.builder()
        .campaign("spring-sale")
        .recipient("user_4821")
        .message(message)
        .track(true, true)
        .build();
CampaignSubmitted answer = mailset.campaigns()
        .submit("news.example.com", List.of(campaign));
System.out.println(answer);
```

Rust:

```rust
use mailset::{CampaignMessage, Message};

// Reads MAILSET_KEY from the environment.
let mailset = mailset::Client::from_env()?;

let fields = Message::builder()
    .from("news@news.example.com")
    .to("maria@example.com")
    .subject("Spring sale")
    .text("Unsubscribe: https://app.example.com/u/4821")
    .header(
        "List-Unsubscribe",
        "<https://app.example.com/u/4821>",
    )
    .header(
        "List-Unsubscribe-Post",
        "List-Unsubscribe=One-Click",
    );
let message = CampaignMessage::new(
    "spring-sale",
    "user_4821",
    fields,
)
.track(true, true);
let answer = mailset
    .campaigns()
    .submit("news.example.com", [message])
    .await?;
println!("{answer:?}");
```

curl:

```bash
curl https://mailset.app/v1/campaigns.submit \
  -H "Authorization: Bearer $TOKEN" \
  -H "ms-time: $MS_TIME" \
  -H "ms-proof: $MS_PROOF" \
  -H "Content-Type: application/json" \
  -d '{"input":{"domain":"news.example.com","messages":[{"raw":"<the message as base64>","campaign":"spring-sale","recipient":"user_4821","track":{"opens":true,"clicks":true}}]},"org":"org_3f9a1c0e7b2d"}'
```

curl can’t sign a request. `$TOKEN` is your credential’s token, and `$MS_TIME` and `$MS_PROOF` sign this exact body: [Calling the API without an SDK](https://mailset.app/docs/authentication/http) shows how. `<the message as base64>` is a whole email, headers and body: [Send your own MIME](https://mailset.app/docs/recipes/mime).

CLI:

```bash
mailset campaigns submit --domain news.example.com --messages @campaign.json
```

`campaign.json`:

```json
[
  {
    "raw": "<the message as base64>",
    "campaign": "spring-sale",
    "recipient": "user_4821",
    "track": {
      "opens": true,
      "clicks": true
    }
  }
]
```

`<the message as base64>` is a whole email, headers and body: [Send your own MIME](https://mailset.app/docs/recipes/mime).

### Response

```json
{
  "ok": true,
  "data": {
    "results": [
      {
        "recipient": "ana@example.com",
        "id": "out_3f9a1c0e7b2d",
        "state": "queued"
      }
    ]
  }
}
```

In the CLI: [mailset reference](https://mailset.app/docs/cli/campaigns#campaigns-submit)

## campaigns.hook.set

Where events go.

`POST /v1/campaigns.hook.set`

A campaigns key for the org. Or a person: an admin or owner of the org.

### Parameters

- `url` (string, required): Where events are POSTed: an https URL on a public host name. At most 500 characters.

Beside `input`:

- `org` (string, optional): The org this is about. Needed when the caller is in more than one.

### Returns

`data` is an object with:

- `secret` (string): The hook’s signing secret, shown this once.

### Request

TypeScript:

```typescript
import { Mailset } from 'mailset';

// Reads MAILSET_KEY from the environment.
const mailset = new Mailset();

const answer = await mailset.campaigns.hook.set({
	url: "https://app.example.com/hooks/campaigns",
});
console.log(answer);
```

Python:

```python
from mailset import Mailset

# Reads MAILSET_KEY from the environment.
mailset = Mailset()

answer = mailset.campaigns.hook.set(
    {"url": "https://app.example.com/hooks/campaigns"}
)
print(answer)
```

Go:

```go
package main

import (
	"context"
	"fmt"
	"log"

	mailset "mailset.app/go"
)

func main() {
	// Reads MAILSET_KEY from the environment.
	client, err := mailset.NewClient()
	if err != nil {
		log.Fatal(err)
	}
	ctx := context.Background()
	params := &mailset.CampaignsHookSetParams{
		URL: "https://app.example.com/hooks/campaigns",
	}
	answer, err := client.Campaigns.Hook.Set(ctx, params)
	if err != nil {
		log.Fatal(err)
	}
	fmt.Println(answer)
}
```

Ruby:

```ruby
require 'mailset'

# Reads MAILSET_KEY from the environment: a campaigns key.
mailset = Mailset::Client.new

answer = mailset.campaigns.hook.set(
  url: 'https://app.example.com/hooks/campaigns'
)
p answer
```

PHP:

```php
<?php

require 'vendor/autoload.php';

// Reads MAILSET_KEY from the environment.
$mailset = new Mailset\Client();

$answer = $mailset->campaigns->hook->set([
    'url' => 'https://app.example.com/hooks/campaigns',
]);
echo json_encode($answer, JSON_PRETTY_PRINT), PHP_EOL;
```

Java:

```java
import app.mailset.Mailset;
import app.mailset.model.CampaignHookSecret;
import app.mailset.model.CampaignsHookSetParams;

// Reads MAILSET_KEY from the environment.
Mailset mailset = Mailset.fromEnv();

var params = CampaignsHookSetParams.builder()
        .url("https://app.example.com/hooks/campaigns")
        .build();
CampaignHookSecret answer =
        mailset.campaigns().hook().set(params);
System.out.println(answer);
```

Rust:

```rust
use mailset::types::CampaignsHookSetParams;

// Reads MAILSET_KEY from the environment.
let mailset = mailset::Client::from_env()?;

let answer = mailset
    .campaigns()
    .hook()
    .set(CampaignsHookSetParams {
        url: "https://app.example.com/hooks/campaigns"
            .into(),
    })
    .await?;
println!("{answer:?}");
```

curl:

```bash
curl https://mailset.app/v1/campaigns.hook.set \
  -H "Authorization: Bearer $TOKEN" \
  -H "ms-time: $MS_TIME" \
  -H "ms-proof: $MS_PROOF" \
  -H "Content-Type: application/json" \
  -d '{"input":{"url":"https://app.example.com/hooks/campaigns"},"org":"org_3f9a1c0e7b2d"}'
```

curl can’t sign a request. `$TOKEN` is your credential’s token, and `$MS_TIME` and `$MS_PROOF` sign this exact body: [Calling the API without an SDK](https://mailset.app/docs/authentication/http) shows how.

CLI:

```bash
mailset campaigns hook set --url https://app.example.com/hooks/campaigns
```

### Response

```json
{
  "ok": true,
  "data": {
    "secret": "whsec_3f9a1c0e7b2d4a58"
  }
}
```

In the CLI: [mailset reference](https://mailset.app/docs/cli/campaigns#campaigns-hook-set)

## campaigns.hook.rotate

A new signing secret for the hook; the old one stops.

`POST /v1/campaigns.hook.rotate`

A campaigns key for the org. Or a person: an admin or owner of the org.

### Parameters

It takes no input: send an empty object.

Beside `input`:

- `org` (string, optional): The org this is about. Needed when the caller is in more than one.

### Returns

`data` is an object with:

- `secret` (string): The hook’s signing secret, shown this once.

### Request

TypeScript:

```typescript
import { Mailset } from 'mailset';

// Reads MAILSET_KEY from the environment.
const mailset = new Mailset();

const answer = await mailset.campaigns.hook.rotate();
console.log(answer);
```

Python:

```python
from mailset import Mailset

# Reads MAILSET_KEY from the environment.
mailset = Mailset()

answer = mailset.campaigns.hook.rotate()
print(answer)
```

Go:

```go
package main

import (
	"context"
	"fmt"
	"log"

	mailset "mailset.app/go"
)

func main() {
	// Reads MAILSET_KEY from the environment.
	client, err := mailset.NewClient()
	if err != nil {
		log.Fatal(err)
	}
	ctx := context.Background()
	answer, err := client.Campaigns.Hook.Rotate(ctx)
	if err != nil {
		log.Fatal(err)
	}
	fmt.Println(answer)
}
```

Ruby:

```ruby
require 'mailset'

# Reads MAILSET_KEY from the environment: a campaigns key.
mailset = Mailset::Client.new

answer = mailset.campaigns.hook.rotate
p answer
```

PHP:

```php
<?php

require 'vendor/autoload.php';

// Reads MAILSET_KEY from the environment.
$mailset = new Mailset\Client();

$answer = $mailset->campaigns->hook->rotate();
echo json_encode($answer, JSON_PRETTY_PRINT), PHP_EOL;
```

Java:

```java
import app.mailset.Mailset;
import app.mailset.model.CampaignHookSecret;

// Reads MAILSET_KEY from the environment.
Mailset mailset = Mailset.fromEnv();

CampaignHookSecret answer =
        mailset.campaigns().hook().rotate();
System.out.println(answer);
```

Rust:

```rust
// Reads MAILSET_KEY from the environment.
let mailset = mailset::Client::from_env()?;

let answer = mailset.campaigns().hook().rotate().await?;
println!("{answer:?}");
```

curl:

```bash
curl https://mailset.app/v1/campaigns.hook.rotate \
  -H "Authorization: Bearer $TOKEN" \
  -H "ms-time: $MS_TIME" \
  -H "ms-proof: $MS_PROOF" \
  -H "Content-Type: application/json" \
  -d '{"input":{},"org":"org_3f9a1c0e7b2d"}'
```

curl can’t sign a request. `$TOKEN` is your credential’s token, and `$MS_TIME` and `$MS_PROOF` sign this exact body: [Calling the API without an SDK](https://mailset.app/docs/authentication/http) shows how.

CLI:

```bash
mailset campaigns hook rotate
```

### Response

```json
{
  "ok": true,
  "data": {
    "secret": "whsec_3f9a1c0e7b2d4a58"
  }
}
```

In the CLI: [mailset reference](https://mailset.app/docs/cli/campaigns#campaigns-hook-rotate)

---

© 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