# GET /mail/trace

First published 14 Oct 2026 (release 0.2.0) · Unchanged since publication

UrbeStack release 0.2.35 API operation in the mail group.

Search the mail logs or trace a single message

- Who may call it: administrator, reseller
- Token scope, any of: mail, read, all
- Answers: 200 OK

An email address search returns matching rows with their statuses, counts by status, the logs searched, any warnings, and an indication of possible account compromise. A queue ID or an angle-bracketed Message-ID returns a single trace under message. If a Message-ID matches multiple queue IDs, the response traces the newest and lists the others.

Use files=true to get retained log metadata without searching the logs. Resellers can search and trace messages only for their own domains and those of their customers.

The API returns 400 if a search omits q or a search parameter fails validation.

## As a command

- [urbestack-mail-trace](https://urbestack.com/docs/commands/urbestack-mail-trace.md): Finds messages in the mail logs and shows what happened to them.

## Parameters

- `q` (query, string, up to 320 characters): Email address to search for, queue ID, or Message-ID enclosed in angle brackets. Required unless files=true, with a maximum of 320 characters and no control characters.
- `files` (query, string, one of true, false): Set to true to return only retained log metadata without reading log contents. The response includes logs, how far back the logs go, the server's current time and time zone, and whether subject logging is enabled.
- `dir` (query, string, one of any, sender, recipient): Direction to match for q, with sender matching the envelope sender or SASL login and recipient matching a recipient. The default is any, which matches either direction.
- `other` (query, string, up to 320 characters): Second email address to restrict the search to messages between it and the email address in q. The maximum length is 320 characters.
- `around` (query, string, up to 19 characters): Center of the search window in the server's time zone, in YYYY-MM-DD HH:MM format.
- `within` (query, string, one of 15m, 1h, 3h, 12h, 24h): Time on each side of around, given as 15m, 1h, 3h, 12h, or 24h. The default is 1h.
- `from` (query, string, up to 19 characters): Start of the search window in the server's time zone, in YYYY-MM-DD HH:MM format. If both around and from are omitted, the search covers the last 24 hours.
- `to` (query, string, up to 19 characters): End of the search window in the server's time zone, in YYYY-MM-DD HH:MM format. The default is the current time.
- `subject` (query, string, up to 200 characters): Text that the logged subject must contain, up to 200 characters.
- `ip` (query, string, up to 45 characters): Client IP address used to send the message, up to 45 characters.
- `sasl` (query, string, up to 320 characters): SASL login used to send the message, up to 320 characters.
- `status` (query, string, one of all, delivered, deferred, bounced, partial, expired, rejected, junk, discarded, deleted): Message status to match. The default is all, which includes every status.
- `rejected` (query, string, one of true, false): Whether to include a row for each connection rejected before Postfix assigned a queue ID. The default is true.
- `limit` (query, integer, 1 to 2000): Maximum number of result rows, with newest rows first. The API accepts whole numbers from 0 to 2000.

## Example

Set $API to the base URL and $TOKEN to the token, as the [API overview](https://urbestack.com/docs/api.md) shows.

```
curl -sS -X GET "$API/mail/trace?q=text&files=true&dir=any&other=text&around=text&within=15m&from=text&to=text&subject=text&ip=203.0.113.7&sasl=text&status=all&rejected=true&limit=1" \
  -H "Authorization: Bearer $TOKEN"
```

Response, 200 OK:

```
{
  "logs": {},
  "message": {
    "at": "text",
    "attempt_count": 1,
    "attempts": [
      {}
    ],
    "bounce": {},
    "bounce_id": "text",
    "client": {},
    "client_history": {},
    "client_host": "text",
    "client_ip": "text",
    "connected_at": "text",
    "customer_text": {},
    "direction": "outbound",
    "epoch": 1,
    "findings": [
      {}
    ],
    "forwarded_from": "text",
    "from": "text",
    "header_from": "text",
    "held": true,
    "helo": "text",
    "in_queue": true,
    "kind": "message",
    "logs": {},
    "mailbox": {},
    "message_id": "text",
    "nrcpt": 1,
    "parent": "example.com",
    "parent_row": {},
    "qid": "text",
    "queued_at": "text",
    "ratelimited": {},
    "raw": {},
    "raw_count": 1,
    "read_at": "text",
    "received_at": "text",
    "recipients": [
      {}
    ],
    "reject_code": "text",
    "reject_dsn": "text",
    "reject_reason": "text",
    "reject_stage": "text",
    "relay": "text",
    "removed_at": "text",
    "same_message_id": [
      "text"
    ],
    "sasl": "text",
    "sasl_method": "text",
    "scan": {},
    "script": "text",
    "server_time": "text",
    "service": "text",
    "session_summary": "text",
    "sessions": [
      {}
    ],
    "size": 1,
    "spam": {},
    "spam_pre": {},
    "spam_score": 1,
    "status": "delivered",
    "subject": "text",
    "subjects_logged": true,
    "timeline": [
      {}
    ],
    "timezone": "text",
    "tls": "text",
    "to": [
      "text"
    ],
    "to_more": 1,
    "total_delay": 1,
    "uid": 1,
    "uid_user": "text",
    "verdict": {}
  },
  "server_time": "text",
  "subjects_logged": true,
  "timezone": "text",
  "trace": {
    "abuse": {},
    "counts": {},
    "logs": {},
    "query": {},
    "read_at": "text",
    "rows": [
      {
        "at": "text",
        "bounce_id": "text",
        "client_host": "text",
        "client_ip": "text",
        "direction": "outbound",
        "epoch": 1,
        "from": "text",
        "header_from": "text",
        "held": true,
        "helo": "text",
        "in_queue": true,
        "kind": "message",
        "message_id": "text",
        "nrcpt": 1,
        "parent": "example.com",
        "qid": "text",
        "raw": {},
        "reject_code": "text",
        "reject_dsn": "text",
        "reject_reason": "text",
        "reject_stage": "text",
        "relay": "text",
        "sasl": "text",
        "size": 1,
        "spam_score": 1,
        "status": "delivered",
        "subject": "text",
        "to": [
          "text"
        ],
        "to_more": 1
      }
    ],
    "scan": {},
    "server_time": "text",
    "shown": 1,
    "subjects_logged": true,
    "timezone": "text",
    "total": 1,
    "warnings": [
      {}
    ],
    "window": {}
  }
}
```

## Errors

- 400: --q, --id, --message-id, --reverse or --files is required
- 400: <what> must be a whole number from 0 to <max>
- 400: <what> must be text without control characters, 1 to <max> characters
- 400: A Message-ID has the shape local@domain
- 400: A queue id is 6 to 20 uppercase hexadecimal characters
- 400: At most 64 addresses at once
- 400: Give an address, a queue id or a Message-ID to search for
- 400: Invalid boolean
- 400: Invalid setting key
- 400: Search for an address, a queue id (6 to 20 uppercase hexadecimal characters) or a Message-ID in angle brackets
- 400: dir is any, sender or recipient
- 400: status is one of the list
- 400: within is 15m, 1h, 3h, 12h or 24h
- 401: Authentication required
- 404: No message <qid> in the kept logs
- 404: No message with the Message-ID <<mid>> in the kept logs
- 404: No such user: <owner>
- 404: Setting '<key>' not found
