Create a transport rule

POST/api/v1/transport-rules
Requires anorganization API keywith the scopetransport_rules:write

Request body

  • namestringrequired

    A name for your team, like Flag mail from outside.

  • conditionsarray<object>required

    What a message must match for the rule to run. At least one.

    • fieldstringrequiredsender | recipient | subject | header | size | has_attachment

      The part of the message to test. size is in bytes.

    • operatorstringrequiredequals | contains | starts_with | ends_with | regex | greater_than | less_than

      How to compare. greater_than and less_than are for size.

    • valuestringrequired

      What to compare with.

  • actionsarray<object>required

    What to do to a matching message. At least one.

    • typestringrequiredadd_header | modify_subject | redirect | bcc | reject | add_disclaimer | quarantine

      What to do. redirect and bcc are accepted but not carried out yet. add_disclaimer adds a header, not text in the email.

    • paramsobject

      Settings for the action. add_header: {"name": "X-Flag", "value": "yes"}. modify_subject: {"prefix": "[External] "}. reject: {"message": "Not accepted"}. add_disclaimer: {"text": "…"}.

  • descriptionstring

    Optional. A note for your team.

  • directionstringinbound | outbound | both

    Which mail the rule looks at: inbound (arriving), outbound (leaving) or both. Defaults to both.

  • condition_logicstringall | any

    How the conditions combine: all must match, or any one is enough. Defaults to all.

  • priorityinteger

    Lower numbers run first. Defaults to 100.

  • enabledboolean

    Whether it is switched on.

Request

POST/api/v1/transport-rules
curl -X POST 'https://app.mailyte.com/api/v1/transport-rules' \
  -H 'Authorization: Bearer mk_live_YOUR_API_KEY' \
  -H 'Content-Type: application/json' \
  -d '{
    "name": "Flag mail from outside",
    "conditions": [
      {
        "field": "sender",
        "operator": "ends_with",
        "value": "@example.com"
      }
    ],
    "actions": [
      {
        "type": "modify_subject",
        "params": {
          "prefix": "[External] "
        }
      }
    ]
  }'
The key names its own organization, so no X-Organization-ID header is needed.

Response

Success.

  • dataobject
    • objectstringtransport_rule
    • idstring

      The rule's ID, a ULID. Rule IDs are uppercase, such as 01M2RV5CEM4MT97RQ00ANRRFCP; compare them exactly.

    • namestring

      The rule's name.

    • descriptionstring

      Your note about the rule. Null when there is none.

    • directionstringinbound | outbound | both

      Which mail the rule checks: inbound, outbound or both (the default).

    • enabledboolean

      A disabled rule keeps its priority and is not evaluated.

    • priorityinteger

      The order rules run in: lower runs first. The default is 100. PUT /transport-rules/reorder renumbers rules in steps of 10, so a rule can be put between two others.

    • matchobject

      How a message is matched: logic and its conditions.

      • logicstringall | any

        all means every condition must match (the default); any means one is enough.

      • conditionsarray<object>

        The conditions, each with field, operator and value.

        • fieldstringsender | recipient | subject | header | size | has_attachment

          What is checked. size is the message size in bytes; has_attachment is true or false.

        • operatorstringequals | contains | starts_with | ends_with | regex | greater_than | less_than

          How value is compared with field.

        • valuestring

          What to compare with. Always a string, even for numbers: a size limit reads back as "1048576". Parse it yourself for greater_than and less_than.

    • actionsarray<object>

      What happens to a matched message, in order.

      • typestringadd_header | modify_subject | redirect | bcc | reject | add_disclaimer | quarantine

        What is done to a message that matches.

      • paramsobject

        The action's settings, keyed by name. Always an object, {} when there are none.

    • created_atstring

      In ISO 8601 UTC.

    • updated_atstring

      In ISO 8601 UTC.

Returned inside the standard envelope.

Errors

StatusWhen
401The API key is missing, unknown, revoked or expired. All four answer identically, on purpose: distinguishing them would confirm which keys exist.
403The key is valid but may not do this: it lacks the required scope, its IP allowlist does not include you, or this endpoint does not accept API keys.
404No such resource in this organization.
422The request was understood but the values were not acceptable.
429Too many requests, or the organization has spent its sending allowance. `Retry-After` says how long to wait.

Every status, with what causes it and what to do, is on the error reference.