Campaigns

Campaigns

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

An SDK signs every request with your key: Authentication. To sign one yourself, see Calling the API without an SDK.

On this page
  1. campaigns.submit
  2. campaigns.hook.set
  3. campaigns.hook.rotate

campaigns.submit

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

POST/v1/campaigns.submit

Campaigns keyAdmin or owner

Parameters

  • domainstringrequired

    The sending domain the messages go from.

  • messagesarray of objectsrequired

    The messages, 1 to 100, each for one recipient.

    1 to 100 items.

    Show child attributesHide child attributes
    • rawstringrequired

      The whole RFC 5322 message, base64, rendered for this one recipient. Up to 1 MB before base64.

      At most 1,398,110 characters.

    • campaignstringrequired

      Your own id for the campaign: 1 to 64 letters, digits, - or _. It comes back on every event.

    • recipientstringrequired

      Your own id for the recipient, in the same form. It comes back on every event.

    • trackobjectrequired

      What to track on this message. Only a domain with a tracking domain can track.

      Show child attributesHide child attributes
      • opensbooleanrequired

        Count when it’s opened.

      • clicksbooleanrequired

        Count clicks on its links.

Beside input

  • orgstringoptional

    The org this is about. Needed when the caller is in more than one.

The body may be up to 67 MB.

Returns

data is an object with:

  • resultsarray of objects

    One result per message, in the order they came.

    Show child attributesHide child attributes
    • recipientstring

      Your id for the recipient, as given.

    • idstringoptional

      Mailset’s id for the message. Its events carry it as message.

    • stateenumoptional

      queued: it will go.

      Alwaysqueued

    • refusedenumoptional

      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 ofsuppressedinvalidpaused

    • reasonstringoptional

      The refusal, in words.

In the CLIErrors

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: "moc.elpmaxe.swen@swen",
			to: "moc.elpmaxe@airam",
			subject: "Spring sale",
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": "moc.elpmaxe.swen@swen",
                "to": "moc.elpmaxe@airam",
                "subject": "Spring sale",
                "text": (
                    "Unsubscribe: "
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{
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: 'moc.elpmaxe.swen@swen',
      to: 'moc.elpmaxe@airam',
      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

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' => 'moc.elpmaxe.swen@swen',
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("moc.elpmaxe.swen@swen")
        .to("moc.elpmaxe@airam")
        .subject("Spring sale")
        .text("Unsubscribe: https://app.example.com/u/482"
                + "1")
        .header("List-Unsubscribe",
                "<https://app.example.com/u/4821>")
use mailset::{CampaignMessage, Message};

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

let fields = Message::builder()
    .from("moc.elpmaxe.swen@swen")
    .to("moc.elpmaxe@airam")
    .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",
    );
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 shows how. <the message as base64> is a whole email, headers and body: Send your own MIME.

mailset campaigns submit --domain news.example.com --messages @campaign.json
campaign.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.

Response
{
  "ok": true,
  "data": {
    "results": [
      {
        "recipient": "moc.elpmaxe@ana",
        "id": "out_3f9a1c0e7b2d",
        "state": "queued"
      }
    ]
  }
}

campaigns.hook.set

Where events go.

POST/v1/campaigns.hook.set

Campaigns keyAdmin or owner

Parameters

  • urlstringrequired

    Where events are POSTed: an https URL on a public host name.

    At most 500 characters.

Beside input

  • orgstringoptional

    The org this is about. Needed when the caller is in more than one.

Returns

data is an object with:

  • secretstring

    The hook’s signing secret, shown this once.

In the CLIErrors

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);
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)
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)
}
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

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;
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);
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 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 shows how.

mailset campaigns hook set --url https://app.example.com/hooks/campaigns
Response
{
  "ok": true,
  "data": {
    "secret": "whsec_3f9a1c0e7b2d4a58"
  }
}

campaigns.hook.rotate

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

POST/v1/campaigns.hook.rotate

Campaigns keyAdmin or owner

Parameters

It takes no input: send an empty object.

Beside input

  • orgstringoptional

    The org this is about. Needed when the caller is in more than one.

Returns

data is an object with:

  • secretstring

    The hook’s signing secret, shown this once.

In the CLIErrors

import { Mailset } from 'mailset';

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

const answer = await mailset.campaigns.hook.rotate();
console.log(answer);
from mailset import Mailset

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

answer = mailset.campaigns.hook.rotate()
print(answer)
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)
}
require 'mailset'

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

answer = mailset.campaigns.hook.rotate
p answer
<?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;
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);
// Reads MAILSET_KEY from the environment.
let mailset = mailset::Client::from_env()?;

let answer = mailset.campaigns().hook().rotate().await?;
println!("{answer:?}");
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 shows how.

mailset campaigns hook rotate
Response
{
  "ok": true,
  "data": {
    "secret": "whsec_3f9a1c0e7b2d4a58"
  }
}