Get your free beta license ↗
API operation · mail group
POST

/domains/{name}/mail/filters

First published 3 Oct 20260.1.0Unchanged since publication

Create a mail filter for the domain or one of its mailboxes

Who may call it
AdministratorResellerCustomer
Token scope, any of
mailall
Answers201 Created

scope defaults to domain. To create a mailbox filter, set scope to account and supply the mailbox's local part in local. Domain filters run before each mailbox's filters. Supply a name of 1 to 64 printable ASCII characters.

Supply 1 to 20 rule objects in rules. Each rule has field, op and value. field can be from, to, subject, header or body. Use header to match any of the usual message headers. op can be contains, not-contains, equals, begins, ends or matches. The matches operator uses shell-style patterns with * and ?. value must contain 1 to 256 characters without ASCII control characters. match defaults to all, which requires every rule to match. Use any to require at least one match.

The action object contains an action field. For folder and redirect, also supply target. folder delivers the message to the target folder, creates it if needed and ends filtering for the message. The folder name must contain 1 to 128 characters without ASCII control characters. discard drops the message. redirect sends a copy to the target email address and keeps the original. For a mailbox filter, the target email address must differ from the mailbox's own. stop skips the remaining filters in the current list.

Filters run in position order, starting at 1. Use position to insert the filter and shift later filters down. position cannot exceed 100. Omit position or give a position past the end to append the filter. The API returns 400 for invalid filter settings. UrbeStack compiles the filter with Pigeonhole before saving it and reports any compilation error. The 201 response contains the new filter in filter.

Administrators, the domain's owner and the owner's reseller can call this operation with a token that has the mail scope.

As a command

Run as root on the server

Parameters

namepath ·DomainNameRequired

Request body

JSON ·MailFilterCreate· 7 fields
actionMailFilterActionRequired
namestring, up to 64 charactersRequired
rulesarray of MailFilterRuleRequired
The part of an email address before the @ is stored in lowercase.
matchstring, one of all, any
positioninteger, 1 to 100
scopestring, one of domain, account
Use domain to run the filter before all mailbox filters in the domain. Use account to run it for the mailbox specified by local.

Example

See the API overview for how to set $API and $TOKEN.
Request
curl -sS -X POST "$API/domains/example.com/mail/filters" \
  -H "Authorization: Bearer $TOKEN" \
  -H "Content-Type: application/json" \
  -d '{
    "action": {
      "action": "folder",
      "target": "https://example.com/new"
    },
    "local": "info",
    "match": "all",
    "name": "alice",
    "position": 1,
    "rules": [
      {
        "field": "from",
        "op": "contains",
        "value": 8443
      }
    ],
    "scope": "domain"
  }'
Response · 201 Created
{
  "filter": {
    "action": {
      "action": "folder",
      "target": "https://example.com/new"
    },
    "address": "info@example.com",
    "created_at": "2026-09-09T10:15:00Z",
    "domain": "example.com",
    "id": 1,
    "name": "alice",
    "position": 1,
    "rules": {}
  }
}

Errors

23 errors, each a status and a sentence
400<what> must be a whole number from 0 to <max>
400<what> must be text without control characters, 1 to <max> characters
400A filter needs one to twenty rules
400A rule is an object with field, op and value
400A rule's field is one of from, to, subject, header, body
400A rule's operator is one of contains, not-contains, equals, begins, ends, matches
400At most <FILTER_MAX> filters here
400Domain name required
400Domain name too long
400Invalid IPv4 address
400Invalid IPv6 address
400Invalid domain name
400Invalid mail address
400Invalid mail address: local part over 64 characters
400Invalid mail address: no local part
400Invalid mail address: the local part may hold letters, digits, dots, _ + and -
400Invalid port
400Invalid setting key
400The action is an object with action and, for folder and redirect, target
400The action is folder, discard, redirect or stop
400match is all or any
401Authentication required
404Setting '<key>' not found
Generated from release 0.2.35 (current) · the API’s own descriptionThis entry has been unchanged since it was first published in release 0.1.0 on 3 Oct 2026.
urbestack.com/docs/api/post-domains-name-mail-filters/