Event hook

Event hook

The webhook that hears what became of your product’s email.

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

On this page
  1. The Event object
  2. hooks.get
  3. hooks.set
  4. hooks.rotate
  5. hooks.remove
  6. hooks.test

The Event object

One thing that happened to one message for one recipient, as your hook receives it.

Attributes

  • idstring

    Stable for this message, recipient and happening, so dedupe on it. For unsubscribed, stable for that opt-out: someone let back in who leaves again has a new one.

  • typeenum

    What happened.

    One ofqueuedsentdeliveredbouncedcomplainedfailedexpiredunsubscribedtest

  • atnumber

    When it happened, in milliseconds since 1970.

  • messagestringoptional

    Mailset’s id for the message: the id its send answered. On every event about a message, and on unsubscribed when the message the link was in is known.

  • messageIdstringoptional

    The message’s Message-ID header, without the angle brackets. Present whenever message is.

  • recipientstringoptional

    The one address this event is about. Absent only on test.

  • appstringoptional

    The app key that sent the mail, by the name it was approved with.

  • duplicateOfstringoptional

    Present when the same content went to this recipient from the same address less than 10 minutes before, under another Message-ID: the message of that earlier send. Both were sent. Give the send an idempotency key to stop it.

  • sendsAtnumberoptional

    queued: when it should go out, in milliseconds since 1970.

  • reasonstringoptional

    queued, failed, expired: why, in words.

  • bounceobjectoptional

    bounced: what kind of bounce it was.

    Show child attributesHide child attributes
    • kindenum

      hard won’t change. soft may go on a later try.

      One ofhardsoft

    • classenum

      What the bounce says about the address: mailbox and domain mean it can’t get mail.

      One ofmailboxdomainfulltoo_largepolicysuppressedother

    • reasonstring

      What the receiving server replied, with its SMTP code. For suppressed, why Mailset didn’t send it.

Where it comes from

Posted to your hook, up to 100 a request

The Event object
{
  "id": "evt_5b1f0c9a7e3d",
  "type": "bounced",
  "at": 1796048940000,
  "message": "out_3f9a1c0e7b2d",
  "messageId": "moc.elpmaxe@85a4d2b7e0c1a9f3",
  "recipient": "gro.elpmaxe@ana",
  "app": "Acme API",
  "bounce": {
    "kind": "hard",
    "class": "mailbox",
    "reason": "smtp; 550 5.1.1 The email account that you tried to reach does not exist."
  }
}

hooks.get

Show where your products’ mail events go, and what waits for the hook.

POST/v1/hooks.get

Admin 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:

  • hooknullable object

    The org’s hook, or null when it has none.

    Show child attributesHide child attributes
    • urlstring

      Where events go.

    • setAtnumber

      When the hook was set, in milliseconds since 1970.

    • waitingnumber

      Events still to hand over.

    • lastErrornullable string

      Why the oldest waiting batch hasn’t gone, when one failed.

In the CLIErrors

import { Mailset } from 'mailset';

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

const answer = await mailset.hooks.get();
console.log(answer);
from mailset import Mailset

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

answer = mailset.hooks.get()
print(answer)
package main

import (
	"context"
	"fmt"
	"log"

	mailset "mailset.app/go"
)

func main() {
	// Reads MAILSET_TOKEN from the environment.
	client, err := mailset.NewClient()
	if err != nil {
		log.Fatal(err)
	}
	ctx := context.Background()
	answer, err := client.Hooks.Get(ctx)
	if err != nil {
		log.Fatal(err)
	}
	fmt.Println(answer)
}
require 'mailset'

# Reads MAILSET_TOKEN from the environment.
mailset = Mailset::Client.new

answer = mailset.hooks.get
p answer
<?php

require 'vendor/autoload.php';

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

$answer = $mailset->hooks->get();
echo json_encode($answer, JSON_PRETTY_PRINT), PHP_EOL;
import app.mailset.Mailset;
import app.mailset.model.HookStatus;

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

HookStatus answer = mailset.hooks().get();
System.out.println(answer);
// Reads MAILSET_TOKEN from the environment.
let mailset = mailset::Client::from_env()?;

let answer = mailset.hooks().get().await?;
println!("{answer:?}");
curl https://mailset.app/v1/hooks.get \
  -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 hooks get
Response
{
  "ok": true,
  "data": {
    "hook": {
      "url": "https://hooks.example.com/mailset",
      "setAt": 1796048940000,
      "waiting": 12,
      "lastError": "text"
    }
  }
}

hooks.set

Send events for your products’ mail to a webhook.

POST/v1/hooks.set

Admin or owner

Parameters

  • urlstringrequired

    Where Mailset posts the events: https, port 443, 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 signing secret, shown this once. Each post’s Mailset-Signature is made with it.

In the CLIErrors

import { Mailset } from 'mailset';

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

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

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

answer = mailset.hooks.set(
    {"url": "https://app.example.com/hooks/mailset"}
)
print(answer)
package main

import (
	"context"
	"fmt"
	"log"

	mailset "mailset.app/go"
)

func main() {
	// Reads MAILSET_TOKEN from the environment.
	client, err := mailset.NewClient()
	if err != nil {
		log.Fatal(err)
	}
	ctx := context.Background()
	params := &mailset.HooksSetParams{
		URL: "https://app.example.com/hooks/mailset",
	}
	answer, err := client.Hooks.Set(ctx, params)
	if err != nil {
		log.Fatal(err)
	}
	fmt.Println(answer)
}
require 'mailset'

# Reads MAILSET_TOKEN from the environment.
mailset = Mailset::Client.new

answer = mailset.hooks.set(
  url: 'https://app.example.com/hooks/mailset'
)
p answer
<?php

require 'vendor/autoload.php';

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

$answer = $mailset->hooks->set([
    'url' => 'https://app.example.com/hooks/mailset',
]);
echo json_encode($answer, JSON_PRETTY_PRINT), PHP_EOL;
import app.mailset.Mailset;
import app.mailset.model.HookSecret;
import app.mailset.model.HooksSetParams;

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

var params = HooksSetParams.builder()
        .url("https://app.example.com/hooks/mailset")
        .build();
HookSecret answer = mailset.hooks().set(params);
System.out.println(answer);
use mailset::types::HooksSetParams;

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

let answer = mailset
    .hooks()
    .set(HooksSetParams {
        url: "https://app.example.com/hooks/mailset"
            .into(),
    })
    .await?;
println!("{answer:?}");
curl https://mailset.app/v1/hooks.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/mailset"},"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 hooks set --url https://app.example.com/hooks/mailset
Response
{
  "ok": true,
  "data": {
    "secret": "whsec_3f9a1c0e7b2d4a58"
  }
}

hooks.rotate

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

POST/v1/hooks.rotate

Admin 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 signing secret, shown this once. Each post’s Mailset-Signature is made with it.

In the CLIErrors

import { Mailset } from 'mailset';

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

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

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

answer = mailset.hooks.rotate()
print(answer)
package main

import (
	"context"
	"fmt"
	"log"

	mailset "mailset.app/go"
)

func main() {
	// Reads MAILSET_TOKEN from the environment.
	client, err := mailset.NewClient()
	if err != nil {
		log.Fatal(err)
	}
	ctx := context.Background()
	answer, err := client.Hooks.Rotate(ctx)
	if err != nil {
		log.Fatal(err)
	}
	fmt.Println(answer)
}
require 'mailset'

# Reads MAILSET_TOKEN from the environment.
mailset = Mailset::Client.new

answer = mailset.hooks.rotate
p answer
<?php

require 'vendor/autoload.php';

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

$answer = $mailset->hooks->rotate();
echo json_encode($answer, JSON_PRETTY_PRINT), PHP_EOL;
import app.mailset.Mailset;
import app.mailset.model.HookSecret;

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

HookSecret answer = mailset.hooks().rotate();
System.out.println(answer);
// Reads MAILSET_TOKEN from the environment.
let mailset = mailset::Client::from_env()?;

let answer = mailset.hooks().rotate().await?;
println!("{answer:?}");
curl https://mailset.app/v1/hooks.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 hooks rotate
Response
{
  "ok": true,
  "data": {
    "secret": "whsec_3f9a1c0e7b2d4a58"
  }
}

hooks.remove

Stop sending product mail events; what was waiting is dropped.

POST/v1/hooks.remove

Admin 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:

  • removedboolean

    True when there was a hook to remove.

In the CLIErrors

import { Mailset } from 'mailset';

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

const answer = await mailset.hooks.remove();
console.log(answer);
from mailset import Mailset

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

answer = mailset.hooks.remove()
print(answer)
package main

import (
	"context"
	"fmt"
	"log"

	mailset "mailset.app/go"
)

func main() {
	// Reads MAILSET_TOKEN from the environment.
	client, err := mailset.NewClient()
	if err != nil {
		log.Fatal(err)
	}
	ctx := context.Background()
	answer, err := client.Hooks.Remove(ctx)
	if err != nil {
		log.Fatal(err)
	}
	fmt.Println(answer)
}
require 'mailset'

# Reads MAILSET_TOKEN from the environment.
mailset = Mailset::Client.new

answer = mailset.hooks.remove
p answer
<?php

require 'vendor/autoload.php';

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

$answer = $mailset->hooks->remove();
echo json_encode($answer, JSON_PRETTY_PRINT), PHP_EOL;
import app.mailset.Mailset;
import app.mailset.model.HooksRemoveResult;

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

HooksRemoveResult answer = mailset.hooks().remove();
System.out.println(answer);
// Reads MAILSET_TOKEN from the environment.
let mailset = mailset::Client::from_env()?;

let answer = mailset.hooks().remove().await?;
println!("{answer:?}");
curl https://mailset.app/v1/hooks.remove \
  -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 hooks remove
Response
{
  "ok": true,
  "data": {
    "removed": true
  }
}

hooks.test

Post one signed test event to the products’ hook now.

POST/v1/hooks.test

Admin 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:

  • urlstring

    Where the test event was posted.

  • tookboolean

    Whether the hook answered 2xx.

  • statusnullable number

    The hook’s HTTP status, or null when it couldn’t be reached.

  • errornullable string

    Why the post wasn’t taken, in a few words, or null.

In the CLIErrors

import { Mailset } from 'mailset';

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

const answer = await mailset.hooks.test();
console.log(answer);
from mailset import Mailset

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

answer = mailset.hooks.test()
print(answer)
package main

import (
	"context"
	"fmt"
	"log"

	mailset "mailset.app/go"
)

func main() {
	// Reads MAILSET_TOKEN from the environment.
	client, err := mailset.NewClient()
	if err != nil {
		log.Fatal(err)
	}
	ctx := context.Background()
	answer, err := client.Hooks.Test(ctx)
	if err != nil {
		log.Fatal(err)
	}
	fmt.Println(answer)
}
require 'mailset'

# Reads MAILSET_TOKEN from the environment.
mailset = Mailset::Client.new

answer = mailset.hooks.test
p answer
<?php

require 'vendor/autoload.php';

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

$answer = $mailset->hooks->test();
echo json_encode($answer, JSON_PRETTY_PRINT), PHP_EOL;
import app.mailset.Mailset;
import app.mailset.model.HookTest;

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

HookTest answer = mailset.hooks().test();
System.out.println(answer);
// Reads MAILSET_TOKEN from the environment.
let mailset = mailset::Client::from_env()?;

let answer = mailset.hooks().test().await?;
println!("{answer:?}");
curl https://mailset.app/v1/hooks.test \
  -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 hooks test
Response
{
  "ok": true,
  "data": {
    "url": "https://hooks.example.com/mailset",
    "took": true,
    "status": 1,
    "error": "text"
  }
}