Rules

Rules

File, label or forward new email as it arrives.

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 Rule object
  2. rules.list
  3. rules.add
  4. rules.update
  5. rules.remove
  6. rules.reorder
  7. rules.test
  8. rules.apply
  9. rules.import

The Rule object

A rule on a mailbox: the email it matches and what it does to it.

Attributes

  • idstring

    The rule’s id.

  • mailboxstring

    The mailbox it runs on.

  • namestring

    The rule’s name.

  • conditionsobject

    What mail it matches. Every part has to hold.

    Show child attributesHide child attributes
    • fromstringoptional

      Mail from this sender.

    • tostringoptional

      Mail sent to this address.

    • subjectstringoptional

      Words in the subject.

    • hasWordsstringoptional

      Words anywhere in it.

    • doesntHavestringoptional

      Words it must not have.

    • hasAttachmentbooleanoptional

      It carries a file.

    • largernumberoptional

      Larger than this many bytes.

    • smallernumberoptional

      Smaller than this many bytes.

  • actionsobject

    What it does to that mail.

    Show child attributesHide child attributes
    • skipInboxbooleanoptional

      Archives it as it arrives.

    • markReadbooleanoptional

      Marks it read.

    • starbooleanoptional

      Stars it.

    • labelstringoptional

      Puts this label on it.

    • forwardstringoptional

      Forwards it to this address.

    • deletebooleanoptional

      Moves it to Trash.

    • neverJunkbooleanoptional

      Never sends it to Junk.

    • importantbooleanoptional

      Marks the conversation important.

    • neverImportantbooleanoptional

      Keeps it from ever being marked important. Beats important.

    • tabenumoptional

      Files it in this inbox tab.

      One ofprimaryupdatesnewsletterspromotions

  • summarystring

    The rule in one line, in the operators it’s written in.

  • matchednumber

    Conversations it has matched or changed.

  • runnullable object

    Its latest run over existing mail, if it has had one.

    Show child attributesHide child attributes
    • idstring

      The run’s id.

    • stateenum

      running, done or failed.

      One ofrunningdonefailed

    • scannednumber

      Conversations looked at so far.

    • changednumber

      Of those, how many the rule changed.

    • reasonnullable string
  • forwardWaitingboolean

    It forwards, and forwarding isn’t on here yet.

Answered by

rules.listrules.addrules.updaterules.reorder

The Rule object
{
  "id": "out_3f9a1c0e7b2d",
  "mailbox": "text",
  "name": "Acme API",
  "conditions": {
    "from": "moc.elpmaxe@olleh",
    "to": "moc.elpmaxe@ana",
    "subject": "Your Acme receipt",
    "hasWords": "text",
    "doesntHave": "text",
    "hasAttachment": true,
    "larger": 1,
    "smaller": 1
  },
  "actions": {
    "skipInbox": true,
    "markRead": true,
    "star": true,

rules.list

List the rules on your mailboxes, in the order they run.

POST/v1/rules.list

API token

Parameters

  • mailboxstringoptional

    Only this mailbox’s rules.

Returns

data is a list of Rule objects.

In the CLIErrors

import { Mailset } from 'mailset';

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

const answer = await mailset.rules.list({
	mailbox: "moc.elpmaxe@ana",
});
console.log(answer);
from mailset import Mailset

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

answer = mailset.rules.list(
    {"mailbox": "moc.elpmaxe@ana"}
)
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.RulesListParams{
		Mailbox: mailset.String("moc.elpmaxe@ana"),
	}
	answer, err := client.Rules.List(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.rules.list(mailbox: 'moc.elpmaxe@ana')
p answer
<?php

require 'vendor/autoload.php';

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

$answer = $mailset->rules->list([
    'mailbox' => 'moc.elpmaxe@ana',
]);
echo json_encode($answer, JSON_PRETTY_PRINT), PHP_EOL;
import app.mailset.Mailset;
import app.mailset.model.Rule;
import app.mailset.model.RulesListParams;
import java.util.List;

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

var params = RulesListParams.builder()
        .mailbox("moc.elpmaxe@ana")
        .build();
List<Rule> answer = mailset.rules().list(params);
System.out.println(answer);
use mailset::types::RulesListParams;

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

let answer = mailset
    .rules()
    .list(RulesListParams {
        mailbox: Some("moc.elpmaxe@ana".into()),
    })
    .await?;
println!("{answer:?}");
curl https://mailset.app/v1/rules.list \
  -H "Authorization: Bearer $TOKEN" \
  -H "ms-time: $MS_TIME" \
  -H "ms-proof: $MS_PROOF" \
  -H "Content-Type: application/json" \
  -d '{"input":{"mailbox":"moc.elpmaxe@ana"}}'

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 rules list --mailbox moc.elpmaxe@ana
Response
{
  "ok": true,
  "data": [
    {
      "id": "out_3f9a1c0e7b2d",
      "mailbox": "text",
      "name": "Acme API",
      "conditions": {
        "from": "moc.elpmaxe@olleh",
        "to": "moc.elpmaxe@ana",
        "subject": "Your Acme receipt",
        "hasWords": "text",
        "doesntHave": "text",
        "hasAttachment": true,
        "larger": 1,
        "smaller": 1
      },
      "actions": {

rules.add

Add a rule.

POST/v1/rules.add

API tokenPasskey

Parameters

  • mailboxstringrequired

    The mailbox the rule runs on.

  • namestringoptional

    A name for the rule, up to 120 characters.

    At most 120 characters.

  • fromstringoptional

    Mail from this sender: an address, a domain or a name.

    At most 1,500 characters.

  • tostringoptional

    Mail sent to this address.

    At most 1,500 characters.

  • subjectstringoptional

    Mail with these words in its subject.

    At most 1,500 characters.

  • hasWordsstringoptional

    Mail with these words anywhere in it.

    At most 1,500 characters.

  • doesntHavestringoptional

    Mail without these words.

    At most 1,500 characters.

  • hasAttachmentbooleanoptional

    Mail that carries a file.

  • largerinteger or stringoptional

    Mail larger than this: bytes, or 5M, 500K.

  • smallerinteger or stringoptional

    Mail smaller than this: bytes, or 5M, 500K.

  • skipInboxbooleanoptional

    Archive it as it arrives.

  • markReadbooleanoptional

    Mark it read.

  • starbooleanoptional

    Star it.

  • labelstring or enumoptional

    Put this label on it, by name.

  • forwardstring or enumoptional

    Forward it to this address. Asks for a passkey.

  • deletebooleanoptional

    Move it to Trash.

  • neverJunkbooleanoptional

    Never send it to Junk.

  • importantbooleanoptional

    Mark it important.

  • neverImportantbooleanoptional

    Never mark it important. Beats important.

  • tabenumoptional

    File it in this inbox tab.

    One ofprimaryupdatesnewsletterspromotions

  • applyExistingbooleanoptional

    Also run it over the conversations already here.

Beside input

  • approvalstringoptional

    An approval’s id, once someone approved it with their passkey. Without one, the answer is step_up_required and names what to approve.

Returns

data is the Rule object.

In the CLIErrors

import { Mailset } from 'mailset';

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

const answer = await mailset.rules.add({
	mailbox: "moc.elpmaxe@ana",
	from: "stripe.com",
	label: "Finance",
	skipInbox: true,
});
console.log(answer);
from mailset import Mailset

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

answer = mailset.rules.add(
    {
        "mailbox": "moc.elpmaxe@ana",
        "from": "stripe.com",
        "label": "Finance",
        "skip_inbox": True,
    }
)
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.RulesAddParams{
require 'mailset'

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

answer = mailset.rules.add(
  mailbox: 'moc.elpmaxe@ana',
  from: 'stripe.com',
  label: 'Finance',
  skip_inbox: true
)
p answer
<?php

require 'vendor/autoload.php';

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

$answer = $mailset->rules->add([
    'mailbox' => 'moc.elpmaxe@ana',
    'from' => 'stripe.com',
    'label' => 'Finance',
    'skipInbox' => true,
]);
echo json_encode($answer, JSON_PRETTY_PRINT), PHP_EOL;
import app.mailset.Mailset;
import app.mailset.model.Rule;
import app.mailset.model.RulesAddParams;

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

var params = RulesAddParams.builder()
        .mailbox("moc.elpmaxe@ana")
        .from("stripe.com")
        .label("Finance")
        .skipInbox(true)
        .build();
Rule answer = mailset.rules().add(params);
System.out.println(answer);
use mailset::types::RulesAddParams;

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

let answer = mailset
    .rules()
    .add(RulesAddParams {
        mailbox: "moc.elpmaxe@ana".into(),
        from: Some("stripe.com".into()),
        skip_inbox: Some(true),
        label: Some("Finance".into()),
        ..Default::default()
    })
    .await?;
println!("{answer:?}");
curl https://mailset.app/v1/rules.add \
  -H "Authorization: Bearer $TOKEN" \
  -H "ms-time: $MS_TIME" \
  -H "ms-proof: $MS_PROOF" \
  -H "Content-Type: application/json" \
  -d '{"input":{"mailbox":"moc.elpmaxe@ana","from":"stripe.com","label":"Finance","skipInbox":true}}'

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 rules add --mailbox moc.elpmaxe@ana --from stripe.com --label Finance --skip-inbox
Response
{
  "ok": true,
  "data": {
    "id": "out_3f9a1c0e7b2d",
    "mailbox": "text",
    "name": "Acme API",
    "conditions": {
      "from": "moc.elpmaxe@olleh",
      "to": "moc.elpmaxe@ana",
      "subject": "Your Acme receipt",
      "hasWords": "text",
      "doesntHave": "text",
      "hasAttachment": true,
      "larger": 1,
      "smaller": 1
    },
    "actions": {
      "skipInbox": true,

rules.update

Change a rule.

POST/v1/rules.update

API tokenPasskey

Parameters

  • idstringrequired

    The rule’s id, from rules list.

  • namestringoptional

    A name for the rule, up to 120 characters.

    At most 120 characters.

  • fromstringoptional

    Mail from this sender: an address, a domain or a name.

    At most 1,500 characters.

  • tostringoptional

    Mail sent to this address.

    At most 1,500 characters.

  • subjectstringoptional

    Mail with these words in its subject.

    At most 1,500 characters.

  • hasWordsstringoptional

    Mail with these words anywhere in it.

    At most 1,500 characters.

  • doesntHavestringoptional

    Mail without these words.

    At most 1,500 characters.

  • hasAttachmentbooleanoptional

    Mail that carries a file.

  • largerinteger or stringoptional

    Mail larger than this: bytes, or 5M, 500K.

  • smallerinteger or stringoptional

    Mail smaller than this: bytes, or 5M, 500K.

  • skipInboxbooleanoptional

    Archive it as it arrives.

  • markReadbooleanoptional

    Mark it read.

  • starbooleanoptional

    Star it.

  • labelstring or enumoptional

    Put this label on it, by name.

  • forwardstring or enumoptional

    Forward it to this address. Asks for a passkey.

  • deletebooleanoptional

    Move it to Trash.

  • neverJunkbooleanoptional

    Never send it to Junk.

  • importantbooleanoptional

    Mark it important.

  • neverImportantbooleanoptional

    Never mark it important. Beats important.

  • tabenumoptional

    File it in this inbox tab.

    One ofprimaryupdatesnewsletterspromotions

  • applyExistingbooleanoptional

    Also run it over the conversations already here.

Beside input

  • approvalstringoptional

    An approval’s id, once someone approved it with their passkey. Without one, the answer is step_up_required and names what to approve.

Returns

data is the Rule object.

In the CLIErrors

import { Mailset } from 'mailset';

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

const answer = await mailset.rules.update({
	label: "Invoices",
	markRead: true,
	id: "rl_1c7e3a9f5b2d4068e4a9c2f1",
});
console.log(answer);
from mailset import Mailset

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

answer = mailset.rules.update(
    {
        "label": "Invoices",
        "mark_read": True,
        "id": "rl_1c7e3a9f5b2d4068e4a9c2f1",
    }
)
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.RulesUpdateParams{
require 'mailset'

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

answer = mailset.rules.update(
  label: 'Invoices',
  mark_read: true,
  id: 'rl_1c7e3a9f5b2d4068e4a9c2f1'
)
p answer
<?php

require 'vendor/autoload.php';

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

$answer = $mailset->rules->update([
    'label' => 'Invoices',
    'markRead' => true,
    'id' => 'rl_1c7e3a9f5b2d4068e4a9c2f1',
]);
echo json_encode($answer, JSON_PRETTY_PRINT), PHP_EOL;
import app.mailset.Mailset;
import app.mailset.model.Rule;
import app.mailset.model.RulesUpdateParams;

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

var params = RulesUpdateParams.builder()
        .label("Invoices")
        .markRead(true)
        .id("rl_1c7e3a9f5b2d4068e4a9c2f1")
        .build();
Rule answer = mailset.rules().update(params);
System.out.println(answer);
use mailset::types::RulesUpdateParams;

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

let answer = mailset
    .rules()
    .update(RulesUpdateParams {
        id: "rl_1c7e3a9f5b2d4068e4a9c2f1".into(),
        mark_read: Some(true),
        label: Some("Invoices".into()),
        ..Default::default()
    })
    .await?;
println!("{answer:?}");
curl https://mailset.app/v1/rules.update \
  -H "Authorization: Bearer $TOKEN" \
  -H "ms-time: $MS_TIME" \
  -H "ms-proof: $MS_PROOF" \
  -H "Content-Type: application/json" \
  -d '{"input":{"label":"Invoices","markRead":true,"id":"rl_1c7e3a9f5b2d4068e4a9c2f1"}}'

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 rules update rl_1c7e3a9f5b2d4068e4a9c2f1 --label Invoices --mark-read
Response
{
  "ok": true,
  "data": {
    "id": "out_3f9a1c0e7b2d",
    "mailbox": "text",
    "name": "Acme API",
    "conditions": {
      "from": "moc.elpmaxe@olleh",
      "to": "moc.elpmaxe@ana",
      "subject": "Your Acme receipt",
      "hasWords": "text",
      "doesntHave": "text",
      "hasAttachment": true,
      "larger": 1,
      "smaller": 1
    },
    "actions": {
      "skipInbox": true,

rules.remove

Delete a rule.

POST/v1/rules.remove

API token

Parameters

  • idstringrequired

    The rule’s id, from rules list.

Returns

data is an object with:

  • removedboolean

In the CLIErrors

import { Mailset } from 'mailset';

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

const answer = await mailset.rules.remove({
	id: "rl_1c7e3a9f5b2d4068e4a9c2f1",
});
console.log(answer);
from mailset import Mailset

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

answer = mailset.rules.remove(
    {"id": "rl_1c7e3a9f5b2d4068e4a9c2f1"}
)
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.RulesRemoveParams{
		ID: "rl_1c7e3a9f5b2d4068e4a9c2f1",
	}
	answer, err := client.Rules.Remove(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.rules.remove(
  id: 'rl_1c7e3a9f5b2d4068e4a9c2f1'
)
p answer
<?php

require 'vendor/autoload.php';

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

$answer = $mailset->rules->remove([
    'id' => 'rl_1c7e3a9f5b2d4068e4a9c2f1',
]);
echo json_encode($answer, JSON_PRETTY_PRINT), PHP_EOL;
import app.mailset.Mailset;
import app.mailset.model.RulesRemoveParams;
import app.mailset.model.RulesRemoveResult;

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

var params = RulesRemoveParams.builder()
        .id("rl_1c7e3a9f5b2d4068e4a9c2f1")
        .build();
RulesRemoveResult answer = mailset.rules().remove(params);
System.out.println(answer);
use mailset::types::RulesRemoveParams;

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

let answer = mailset
    .rules()
    .remove(RulesRemoveParams {
        id: "rl_1c7e3a9f5b2d4068e4a9c2f1".into(),
    })
    .await?;
println!("{answer:?}");
curl https://mailset.app/v1/rules.remove \
  -H "Authorization: Bearer $TOKEN" \
  -H "ms-time: $MS_TIME" \
  -H "ms-proof: $MS_PROOF" \
  -H "Content-Type: application/json" \
  -d '{"input":{"id":"rl_1c7e3a9f5b2d4068e4a9c2f1"}}'

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 rules remove rl_1c7e3a9f5b2d4068e4a9c2f1
Response
{
  "ok": true,
  "data": {
    "removed": true
  }
}

rules.reorder

Set the order a mailbox’s rules run in.

POST/v1/rules.reorder

API token

Parameters

  • mailboxstringrequired

    The mailbox whose rules these are.

  • idsarray of stringsrequired

    Every rule’s id, in the order they should run.

    1 to 1,000 items.

Returns

data is a list of Rule objects.

In the CLIErrors

import { Mailset } from 'mailset';

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

const answer = await mailset.rules.reorder({
	mailbox: "moc.elpmaxe@ana",
	ids: [
		"rl_9a2f6c1e8b4d3057c1e6a3b8",
		"rl_1c7e3a9f5b2d4068e4a9c2f1",
	],
});
console.log(answer);
from mailset import Mailset

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

answer = mailset.rules.reorder(
    {
        "mailbox": "moc.elpmaxe@ana",
        "ids": [
            "rl_9a2f6c1e8b4d3057c1e6a3b8",
            "rl_1c7e3a9f5b2d4068e4a9c2f1",
        ],
    }
)
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.RulesReorderParams{
require 'mailset'

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

answer = mailset.rules.reorder(
  mailbox: 'moc.elpmaxe@ana',
  ids: [
    'rl_9a2f6c1e8b4d3057c1e6a3b8',
    'rl_1c7e3a9f5b2d4068e4a9c2f1'
  ]
)
p answer
<?php

require 'vendor/autoload.php';

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

$answer = $mailset->rules->reorder([
    'mailbox' => 'moc.elpmaxe@ana',
    'ids' => [
        'rl_9a2f6c1e8b4d3057c1e6a3b8',
        'rl_1c7e3a9f5b2d4068e4a9c2f1',
    ],
]);
echo json_encode($answer, JSON_PRETTY_PRINT), PHP_EOL;
import app.mailset.Mailset;
import app.mailset.model.Rule;
import app.mailset.model.RulesReorderParams;
import java.util.List;

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

var params = RulesReorderParams.builder()
        .mailbox("moc.elpmaxe@ana")
        .ids(List.of(
                "rl_9a2f6c1e8b4d3057c1e6a3b8",
                "rl_1c7e3a9f5b2d4068e4a9c2f1"))
        .build();
List<Rule> answer = mailset.rules().reorder(params);
System.out.println(answer);
use mailset::types::RulesReorderParams;

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

let answer = mailset
    .rules()
    .reorder(RulesReorderParams {
        mailbox: "moc.elpmaxe@ana".into(),
        ids: vec![
            "rl_9a2f6c1e8b4d3057c1e6a3b8".into(),
            "rl_1c7e3a9f5b2d4068e4a9c2f1".into(),
        ],
    })
    .await?;
println!("{answer:?}");
curl https://mailset.app/v1/rules.reorder \
  -H "Authorization: Bearer $TOKEN" \
  -H "ms-time: $MS_TIME" \
  -H "ms-proof: $MS_PROOF" \
  -H "Content-Type: application/json" \
  -d '{"input":{"mailbox":"moc.elpmaxe@ana","ids":["rl_9a2f6c1e8b4d3057c1e6a3b8","rl_1c7e3a9f5b2d4068e4a9c2f1"]}}'

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 rules reorder --mailbox moc.elpmaxe@ana --ids rl_9a2f6c1e8b4d3057c1e6a3b8,rl_1c7e3a9f5b2d4068e4a9c2f1
Response
{
  "ok": true,
  "data": [
    {
      "id": "out_3f9a1c0e7b2d",
      "mailbox": "text",
      "name": "Acme API",
      "conditions": {
        "from": "moc.elpmaxe@olleh",
        "to": "moc.elpmaxe@ana",
        "subject": "Your Acme receipt",
        "hasWords": "text",
        "doesntHave": "text",
        "hasAttachment": true,
        "larger": 1,
        "smaller": 1
      },
      "actions": {

rules.test

Show what a rule would match, without doing anything.

POST/v1/rules.test

API token

Parameters

  • idstringoptional

    A rule you have, by its id. Left out: the flags describe one.

  • mailboxstringoptional

    The mailbox to test against, for a rule described by flags.

  • namestringoptional

    A name for the rule, up to 120 characters.

    At most 120 characters.

  • fromstringoptional

    Mail from this sender: an address, a domain or a name.

    At most 1,500 characters.

  • tostringoptional

    Mail sent to this address.

    At most 1,500 characters.

  • subjectstringoptional

    Mail with these words in its subject.

    At most 1,500 characters.

  • hasWordsstringoptional

    Mail with these words anywhere in it.

    At most 1,500 characters.

  • doesntHavestringoptional

    Mail without these words.

    At most 1,500 characters.

  • hasAttachmentbooleanoptional

    Mail that carries a file.

  • largerinteger or stringoptional

    Mail larger than this: bytes, or 5M, 500K.

  • smallerinteger or stringoptional

    Mail smaller than this: bytes, or 5M, 500K.

  • skipInboxbooleanoptional

    Archive it as it arrives.

  • markReadbooleanoptional

    Mark it read.

  • starbooleanoptional

    Star it.

  • labelstring or enumoptional

    Put this label on it, by name.

  • forwardstring or enumoptional

    Forward it to this address. Asks for a passkey.

  • deletebooleanoptional

    Move it to Trash.

  • neverJunkbooleanoptional

    Never send it to Junk.

  • importantbooleanoptional

    Mark it important.

  • neverImportantbooleanoptional

    Never mark it important. Beats important.

  • tabenumoptional

    File it in this inbox tab.

    One ofprimaryupdatesnewsletterspromotions

Returns

data is an object with:

  • matchednumber
  • samplearray of Conversation objects

    The newest few, to check by eye.

  • cappedboolean

    The count stopped at the scan limit, so there may be more.

In the CLIErrors

import { Mailset } from 'mailset';

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

const answer = await mailset.rules.test({
	mailbox: "moc.elpmaxe@ana",
	from: "stripe.com",
});
console.log(answer);
from mailset import Mailset

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

answer = mailset.rules.test(
    {"mailbox": "moc.elpmaxe@ana", "from": "stripe.com"}
)
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.RulesTestParams{
		Mailbox: mailset.String("moc.elpmaxe@ana"),
		From:    mailset.String("stripe.com"),
	}
	answer, err := client.Rules.Test(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.rules.test(
  mailbox: 'moc.elpmaxe@ana',
  from: 'stripe.com'
)
p answer
<?php

require 'vendor/autoload.php';

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

$answer = $mailset->rules->test([
    'mailbox' => 'moc.elpmaxe@ana',
    'from' => 'stripe.com',
]);
echo json_encode($answer, JSON_PRETTY_PRINT), PHP_EOL;
import app.mailset.Mailset;
import app.mailset.model.RuleTest;
import app.mailset.model.RulesTestParams;

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

var params = RulesTestParams.builder()
        .mailbox("moc.elpmaxe@ana")
        .from("stripe.com")
        .build();
RuleTest answer = mailset.rules().test(params);
System.out.println(answer);
use mailset::types::RulesTestParams;

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

let answer = mailset
    .rules()
    .test(RulesTestParams {
        mailbox: Some("moc.elpmaxe@ana".into()),
        from: Some("stripe.com".into()),
        ..Default::default()
    })
    .await?;
println!("{answer:?}");
curl https://mailset.app/v1/rules.test \
  -H "Authorization: Bearer $TOKEN" \
  -H "ms-time: $MS_TIME" \
  -H "ms-proof: $MS_PROOF" \
  -H "Content-Type: application/json" \
  -d '{"input":{"mailbox":"moc.elpmaxe@ana","from":"stripe.com"}}'

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 rules test --mailbox moc.elpmaxe@ana --from stripe.com
Response
{
  "ok": true,
  "data": {
    "matched": 1,
    "sample": [
      {
        "id": "out_3f9a1c0e7b2d",
        "mailbox": "text",
        "from": "moc.elpmaxe@olleh",
        "fromAddress": "moc.elpmaxe@olleh",
        "subject": "Your Acme receipt",
        "snippet": "text",
        "count": 12,
        "latestAt": 1796048940000,
        "unread": true,
        "starred": true,
        "important": true,
        "place": "inbox",

rules.apply

Run a rule over the conversations already here, in the background.

POST/v1/rules.apply

API token

Parameters

  • idstringrequired

    The rule’s id, from rules list.

Returns

data is an object with:

  • idstring

    The run’s id.

  • stateenum

    running, done or failed.

    One ofrunningdonefailed

  • scannednumber

    Conversations looked at so far.

  • changednumber

    Of those, how many the rule changed.

  • reasonnullable string

In the CLIErrors

import { Mailset } from 'mailset';

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

const answer = await mailset.rules.apply({
	id: "rl_1c7e3a9f5b2d4068e4a9c2f1",
});
console.log(answer);
from mailset import Mailset

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

answer = mailset.rules.apply(
    {"id": "rl_1c7e3a9f5b2d4068e4a9c2f1"}
)
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.RulesApplyParams{
		ID: "rl_1c7e3a9f5b2d4068e4a9c2f1",
	}
	answer, err := client.Rules.Apply(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.rules.apply(
  id: 'rl_1c7e3a9f5b2d4068e4a9c2f1'
)
p answer
<?php

require 'vendor/autoload.php';

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

$answer = $mailset->rules->apply([
    'id' => 'rl_1c7e3a9f5b2d4068e4a9c2f1',
]);
echo json_encode($answer, JSON_PRETTY_PRINT), PHP_EOL;
import app.mailset.Mailset;
import app.mailset.model.RuleRun;
import app.mailset.model.RulesApplyParams;

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

var params = RulesApplyParams.builder()
        .id("rl_1c7e3a9f5b2d4068e4a9c2f1")
        .build();
RuleRun answer = mailset.rules().apply(params);
System.out.println(answer);
use mailset::types::RulesApplyParams;

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

let answer = mailset
    .rules()
    .apply(RulesApplyParams {
        id: "rl_1c7e3a9f5b2d4068e4a9c2f1".into(),
    })
    .await?;
println!("{answer:?}");
curl https://mailset.app/v1/rules.apply \
  -H "Authorization: Bearer $TOKEN" \
  -H "ms-time: $MS_TIME" \
  -H "ms-proof: $MS_PROOF" \
  -H "Content-Type: application/json" \
  -d '{"input":{"id":"rl_1c7e3a9f5b2d4068e4a9c2f1"}}'

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 rules apply rl_1c7e3a9f5b2d4068e4a9c2f1
Response
{
  "ok": true,
  "data": {
    "id": "out_3f9a1c0e7b2d",
    "state": "running",
    "scanned": 1,
    "changed": 1,
    "reason": "The day’s sending limit is reached."
  }
}

rules.import

Turn a Gmail mailFilters.xml export into rules.

POST/v1/rules.import

API tokenPasskey

Parameters

  • mailboxstringrequired

    The mailbox the rules go on.

  • namestringrequired

    The file’s name.

    At most 255 characters.

  • datastringrequired

    The file, base64.

Beside input

  • approvalstringoptional

    An approval’s id, once someone approved it with their passkey. Without one, the answer is step_up_required and names what to approve.

The body may be up to 8 MB.

Returns

data is an object with:

  • importednumber
  • skippednumber
  • itemsarray of objects
    Show child attributesHide child attributes
    • filterstring

      The filter in the file’s own words: from:a subject:b.

    • rulenullable string

      Null when it wasn’t imported.

    • notesarray of strings

      Why it, or a part of it, was left out.

In the CLIErrors

import { Mailset } from 'mailset';

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

const answer = await mailset.rules.import({
	mailbox: "moc.elpmaxe@ana",
	name: "mailFilters.xml",
	data: "<the message as base64>",
});
console.log(answer);

<the message as base64> is a whole email, headers and body: Send your own MIME.

from mailset import Mailset

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

answer = mailset.rules.import_rules(
    {
        "mailbox": "moc.elpmaxe@ana",
        "name": "mailFilters.xml",
        "data": "<the message as base64>",
    }
)
print(answer)

<the message as base64> is a whole email, headers and body: Send your own MIME.

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.RulesImportParams{

<the message as base64> is a whole email, headers and body: Send your own MIME.

require 'mailset'

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

answer = mailset.rules.import(
  mailbox: 'moc.elpmaxe@ana',
  name: 'mailFilters.xml',
  data: '<the message as base64>'
)
p answer

<the message as base64> is a whole email, headers and body: Send your own MIME.

<?php

require 'vendor/autoload.php';

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

$answer = $mailset->rules->import([
    'mailbox' => 'moc.elpmaxe@ana',
    'name' => 'mailFilters.xml',
    'data' => '<the message as base64>',
]);
echo json_encode($answer, JSON_PRETTY_PRINT), PHP_EOL;

<the message as base64> is a whole email, headers and body: Send your own MIME.

import app.mailset.Mailset;
import app.mailset.model.RuleImportReport;
import app.mailset.model.RulesImportParams;

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

var params = RulesImportParams.builder()
        .mailbox("moc.elpmaxe@ana")
        .name("mailFilters.xml")
        .data("<the message as base64>")
        .build();
RuleImportReport answer =
        mailset.rules().importRules(params);
System.out.println(answer);

<the message as base64> is a whole email, headers and body: Send your own MIME.

use mailset::types::RulesImportParams;

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

let answer = mailset
    .rules()
    .import(RulesImportParams {
        mailbox: "moc.elpmaxe@ana".into(),
        name: "mailFilters.xml".into(),
        data: "<the message as base64>".into(),
    })
    .await?;
println!("{answer:?}");

<the message as base64> is a whole email, headers and body: Send your own MIME.

curl https://mailset.app/v1/rules.import \
  -H "Authorization: Bearer $TOKEN" \
  -H "ms-time: $MS_TIME" \
  -H "ms-proof: $MS_PROOF" \
  -H "Content-Type: application/json" \
  -d '{"input":{"mailbox":"moc.elpmaxe@ana","name":"mailFilters.xml","data":"<base64 of the file>"}}'

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 rules import moc.elpmaxe@ana --file mailFilters.xml
Response
{
  "ok": true,
  "data": {
    "imported": 1,
    "skipped": 1,
    "items": [
      {
        "filter": "text",
        "rule": "text",
        "notes": [
          "text"
        ]
      }
    ]
  }
}