Receive Emails: Rules

Create Rule

Create a filter that runs on every new email: match by sender, domain, provider, subject, body, attachments, time and more, then move, label, flag, snooze or reply.

POSThttps://g.sendcorex.com/v1command: create_rule
i

The new rule goes to the end of the list. Rules run in order; stop: true skips the rules below it when it matches.

!

A rule cannot take an email out of Spam, trust or block the sender, or reply automatically unless the From domain passed SPF or DKIM aligned (or DMARC). Anyone can write From: boss@yourcompany.com; without this check that email would skip your filters or block your boss.

Arguments

  • namestringrequired

    Up to 80 characters.

  • conditionsobject[]required

    [{ field, op, value, header? }]. 1 to 20 (counting exceptions).

  • matchstringoptional

    all (default) or any of the conditions.

  • exceptobject[]optional

    If any of these match, the rule does not run.

  • actionsobject[]required

    [{ type, value? }]. 1 to 12. Only one move.

  • stopbooleanoptional

    Do not run the rules below when this one matches.

  • enabledbooleanoptional

    Defaults to true.

  • timezonestringoptional

    IANA name used by received_hour, received_weekday and next_morning. Defaults to UTC.

  • presetstringoptional

    Your own tag for rules created from a template.

Quick start

import axios from 'axios';

const response = await axios.post(
  'https://g.sendcorex.com/v1',
  {
    commands: [
      {
        command: "create_rule",
        args: {
          name: "Clients always in Inbox",
          match: "all",
          conditions: [
            {
              field: "from_domain",
              op: "in_list",
              value: "acme.com, globex.com"
            },
            {
              field: "provider",
              op: "is_any_of",
              value: [
                "microsoft_365",
                "google_workspace"
              ]
            }
          ],
          except: [
            {
              field: "subject",
              op: "contains",
              value: "newsletter"
            }
          ],
          actions: [
            {
              type: "keep_inbox"
            },
            {
              type: "label",
              value: "Clients"
            },
            {
              type: "star"
            }
          ],
          stop: false,
          timezone: "Asia/Kuala_Lumpur"
        }
      }
    ]
  },
  { headers: { Authorization: process.env.SENDCOREX_TOKEN } },
);

const [result] = response.data.results;
if (result.type !== 'SUCCESS') throw new Error(`${result.code}: ${result.message}`);
console.log(result.data);

Response

{
  "type": "SUCCESS",
  "results": [
    {
      "command": "create_rule",
      "id": "0",
      "type": "SUCCESS",
      "data": {
        "id": "Vj0xUlVMRTAx",
        "rule_id": "Vj0xUlVMRTAx",
        "name": "Clients always in Inbox",
        "match": "all",
        "conditions": [
          {
            "field": "from_domain",
            "op": "in_list",
            "value": "acme.com, globex.com"
          },
          {
            "field": "provider",
            "op": "is_any_of",
            "value": [
              "microsoft_365",
              "google_workspace"
            ]
          }
        ],
        "except": [
          {
            "field": "subject",
            "op": "contains",
            "value": "newsletter"
          }
        ],
        "actions": [
          {
            "type": "keep_inbox"
          },
          {
            "type": "label",
            "value": "Clients"
          },
          {
            "type": "star"
          }
        ],
        "stop": false,
        "timezone": "Asia/Kuala_Lumpur",
        "enabled": true,
        "position": 0,
        "hits": 128,
        "last_hit_at": "2026-10-25T09:12:44Z",
        "created_at": "2026-10-01T02:00:00Z",
        "updated_at": "2026-10-20T08:30:00Z"
      }
    }
  ]
}

Fields and operators

  • from / from_name / reply_to

    text: contains, not_contains, is, is_not, starts_with, ends_with, regex, not_regex, in_list, not_in_list, is_empty, not_empty

  • from_domain

    domain: is (also matches subdomains), is_not, in_list, not_in_list, contains, not_contains, ends_with, regex, not_regex

  • to / cc / recipient

    list of addresses (recipient = to + cc). Same operators as text; matches when any address matches

  • subject / body / subject_or_body

    text. The body is read up to the first 20,000 characters

  • attachment_name / attachment_type

    list. attachment_type is the extension: pdf, xlsx…

  • list_id

    text. The List-Id of a mailing list

  • header

    text, with the header name in header (e.g. x-mailer). Only checked when the email arrives

  • provider

    is_any_of / is_none_of: google_workspace, gmail, microsoft_365, outlook, yahoo, icloud, zoho, proton, amazon_ses, sendgrid, mailgun, other

  • received_weekday

    is_any_of / is_none_of: sun, mon, tue, wed, thu, fri, sat (in the rule timezone)

  • received_hour

    gt, lt, between, not_between. 22-6 crosses midnight

  • size_kb

    gt, lt, between, not_between

  • has_attachment, is_mailing_list, is_reply, is_auto_reply, is_calendar_invite, authenticated, trusted_sender, first_time_sender, only_to_me

    is_true / is_false

Actions

  • move

    value: inbox, archive, spam, trash, promotions or custom:<folder-id>. The first rule that moves wins

  • keep_inbox

    Always Inbox: never Spam, triage (Agents / NotSubscribing) or Promotions

  • mark_read / star / important

    Flags. They add up across rules

  • label

    value: the label name (1–50 characters). Labels add up across rules

  • trust_sender / block_sender

    Saves the sender as trusted or blocked for the next emails. block_sender also moves to Spam

  • snooze

    value: hours (1 to 8760) or next_morning (next 8:00 in the rule timezone). Only for emails that stay in Inbox

  • auto_reply

    value: a template id. One reply per sender every 24 hours

i

When several rules match: the first move wins, labels and flags add up, and block_sender overrides trust_sender.

What a rule cannot override

!

A rule cannot take an email out of Spam, trust or block the sender, or reply automatically unless the From domain passed SPF or DKIM aligned (or DMARC). Anyone can write From: boss@yourcompany.com; without this check that email would skip your filters or block your boss.

i

Labels, read, star and moving to Spam or Trash always apply. Phishing reports, DMARC quarantine, a sender you blocked by hand and a list you unsubscribed from keep the email in Spam whatever the rule says.

i

provider comes from the delivery path that we verify: the server that connected to us (reverse DNS confirmed forward) and SPF passing through the provider's own range. The MX record is never used: anyone can point MX to Google and send from their own server.

Values

in_list takes a list separated by comma, semicolon or new line. In address lists, @acme.com matches anyone at that domain. regex uses RE2: no lookahead, lookbehind or backreferences, up to 300 characters. Text comparisons ignore case.

Errors

HTTP-level errors return type, code and message. Errors marked CMD come back inside the command result, with HTTP 200.

  • 401TOKEN_EXPIRED

    The access token has expired. Call Refresh Token and repeat the request.

  • 401INVALID_TOKEN

    The token is malformed, unknown or revoked.

  • 429RATE_LIMITED

    More than 15 requests/s or 15 in flight for the same IP + mailbox. Wait the number of seconds in Retry-After.

  • CMDINVALID_ARGS

    A required argument is missing or invalid.

  • CMDINVALID_RULE

    The rule is not valid. The message says which condition or action and why.

  • CMDLIMIT

    The mailbox reached the limit (100 rules, 200 templates or 100 labels).

  • CMDINTERNAL

    Server error. The detail is only written to the server log.