# Event hook

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

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).

## The Event object

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

### Attributes

- `id` (string): 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.
- `type` (enum): What happened. One of `queued`, `sent`, `delivered`, `bounced`, `complained`, `failed`, `expired`, `unsubscribed`, `test`.
- `at` (number): When it happened, in milliseconds since 1970.
- `message` (string, optional): 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.
- `messageId` (string, optional): The message’s Message-ID header, without the angle brackets. Present whenever `message` is.
- `recipient` (string, optional): The one address this event is about. Absent only on `test`.
- `app` (string, optional): The app key that sent the mail, by the name it was approved with.
- `duplicateOf` (string, optional): 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.
- `sendsAt` (number, optional): `queued`: when it should go out, in milliseconds since 1970.
- `reason` (string, optional): `queued`, `failed`, `expired`: why, in words.
- `bounce` (object, optional): `bounced`: what kind of bounce it was.
  - `kind` (enum): `hard` won’t change. `soft` may go on a later try. One of `hard`, `soft`.
  - `class` (enum): What the bounce says about the address: `mailbox` and `domain` mean it can’t get mail. One of `mailbox`, `domain`, `full`, `too_large`, `policy`, `suppressed`, `other`.
  - `reason` (string): What the receiving server replied, with its SMTP code. For `suppressed`, why Mailset didn’t send it.

```json
{
  "id": "evt_5b1f0c9a7e3d",
  "type": "bounced",
  "at": 1796048940000,
  "message": "out_3f9a1c0e7b2d",
  "messageId": "3f9a1c0e7b2d4a58@example.com",
  "recipient": "ana@example.org",
  "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."
  }
}
```

Posted to your hook, up to 100 a request: [Webhooks](https://mailset.app/docs/webhooks)

## hooks.get

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

`POST /v1/hooks.get`

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:

- `hook` (nullable object): The org’s hook, or null when it has none.
  - `url` (string): Where events go.
  - `setAt` (number): When the hook was set, in milliseconds since 1970.
  - `waiting` (number): Events still to hand over.
  - `lastError` (nullable string): Why the oldest waiting batch hasn’t gone, when one failed.

### Request

TypeScript:

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

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

const answer = await mailset.hooks.get();
console.log(answer);
```

Python:

```python
from mailset import Mailset

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

answer = mailset.hooks.get()
print(answer)
```

Go:

```go
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)
}
```

Ruby:

```ruby
require 'mailset'

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

answer = mailset.hooks.get
p answer
```

PHP:

```php
<?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;
```

Java:

```java
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);
```

Rust:

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

let answer = mailset.hooks().get().await?;
println!("{answer:?}");
```

curl:

```bash
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](https://mailset.app/docs/authentication/http) shows how.

CLI:

```bash
mailset hooks get
```

### Response

```json
{
  "ok": true,
  "data": {
    "hook": {
      "url": "https://hooks.example.com/mailset",
      "setAt": 1796048940000,
      "waiting": 12,
      "lastError": "text"
    }
  }
}
```

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

## hooks.set

Send events for your products’ mail to a webhook.

`POST /v1/hooks.set`

An admin or owner of the org.

### Parameters

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

### Request

TypeScript:

```typescript
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);
```

Python:

```python
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)
```

Go:

```go
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)
}
```

Ruby:

```ruby
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:

```php
<?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;
```

Java:

```java
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);
```

Rust:

```rust
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:

```bash
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](https://mailset.app/docs/authentication/http) shows how.

CLI:

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

### Response

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

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

## hooks.rotate

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

`POST /v1/hooks.rotate`

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

### Request

TypeScript:

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

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

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

Python:

```python
from mailset import Mailset

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

answer = mailset.hooks.rotate()
print(answer)
```

Go:

```go
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)
}
```

Ruby:

```ruby
require 'mailset'

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

answer = mailset.hooks.rotate
p answer
```

PHP:

```php
<?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;
```

Java:

```java
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);
```

Rust:

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

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

curl:

```bash
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](https://mailset.app/docs/authentication/http) shows how.

CLI:

```bash
mailset hooks rotate
```

### Response

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

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

## hooks.remove

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

`POST /v1/hooks.remove`

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:

- `removed` (boolean): True when there was a hook to remove.

### Request

TypeScript:

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

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

const answer = await mailset.hooks.remove();
console.log(answer);
```

Python:

```python
from mailset import Mailset

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

answer = mailset.hooks.remove()
print(answer)
```

Go:

```go
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)
}
```

Ruby:

```ruby
require 'mailset'

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

answer = mailset.hooks.remove
p answer
```

PHP:

```php
<?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;
```

Java:

```java
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);
```

Rust:

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

let answer = mailset.hooks().remove().await?;
println!("{answer:?}");
```

curl:

```bash
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](https://mailset.app/docs/authentication/http) shows how.

CLI:

```bash
mailset hooks remove
```

### Response

```json
{
  "ok": true,
  "data": {
    "removed": true
  }
}
```

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

## hooks.test

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

`POST /v1/hooks.test`

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:

- `url` (string): Where the test event was posted.
- `took` (boolean): Whether the hook answered 2xx.
- `status` (nullable number): The hook’s HTTP status, or null when it couldn’t be reached.
- `error` (nullable string): Why the post wasn’t taken, in a few words, or null.

### Request

TypeScript:

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

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

const answer = await mailset.hooks.test();
console.log(answer);
```

Python:

```python
from mailset import Mailset

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

answer = mailset.hooks.test()
print(answer)
```

Go:

```go
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)
}
```

Ruby:

```ruby
require 'mailset'

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

answer = mailset.hooks.test
p answer
```

PHP:

```php
<?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;
```

Java:

```java
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);
```

Rust:

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

let answer = mailset.hooks().test().await?;
println!("{answer:?}");
```

curl:

```bash
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](https://mailset.app/docs/authentication/http) shows how.

CLI:

```bash
mailset hooks test
```

### Response

```json
{
  "ok": true,
  "data": {
    "url": "https://hooks.example.com/mailset",
    "took": true,
    "status": 1,
    "error": "text"
  }
}
```

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

---

© 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