---
title: "Receiving mail"
description: "How a message becomes a thread, a message and an event: attachments and their text, the raw and HTML bodies, categories, verdicts and the auto-replyable flag, threading and duplicates."
url: https://doorman.fyi/docs/receiving
markdown: https://doorman.fyi/docs/receiving.md
area: "Guides"
section: "Mail"
---

# Receiving mail

How a message becomes a thread, a message and an event: attachments and their text, the raw and HTML bodies, categories, verdicts and the auto-replyable flag, threading and duplicates.

Source: https://doorman.fyi/docs/receiving

## What happens when mail arrives

Mail for an active inbox is accepted at the mail server and goes through one pipeline before anything is stored: the message is parsed, duplicates are dropped by their `Message-ID`, the thread is chosen, the message is classified, the original, the HTML body and the attachments are stored, text is extracted from the attachments, and one transaction writes the thread, the message, the attachments and the `message.received` event. The event is then pushed to the stream and queued for the webhooks.

Mail for an unknown address, mail larger than 25 MiB and mail that cannot be parsed are rejected at the mail server, so the sender learns at once. A passing fault is answered with a temporary failure so the sender's server retries later. Receiving is never counted against a plan.

Where a deployment runs the malware engine or the link sandbox and enforces security policies, a message with an attachment or a suspect link is stored first and announced a little later: its event fires once, when the check is in, usually within seconds. See [Attachments and links](https://doorman.fyi/docs/security.md#files).

## Threads

A thread is a conversation. [`GET /v1/inboxes/{inboxId}/threads`](https://doorman.fyi/docs/reference/mail.md#inboxes-threads-list) lists an inbox's threads, newest activity first, with `limit` (50 by default, at most 100), `offset` and `total`. `isRead=false` keeps the threads waiting on the agent; `q` keeps the threads whose subject or a participant address contains the text.

A [`Thread`](https://doorman.fyi/docs/reference/schemas.md#Thread) carries the subject of its first message, the addresses that took part in it, the message count, `isRead`, the instants of its first and last messages and the id of the last one. [`PATCH /v1/threads/{threadId}`](https://doorman.fyi/docs/reference/mail.md#threads-update) with `{ "isRead": true }` marks it read; sending a reply marks it read as well, as a mail client would.

[`DELETE /v1/threads/{threadId}`](https://doorman.fyi/docs/reference/mail.md#threads-trash) trashes a thread: it and its messages leave every list and read, a reply to it answers `404 thread_not_found`, and a later message in the same conversation starts a new thread. Nothing is erased until the retention sweep exists.

## Messages

[`GET /v1/threads/{threadId}/messages`](https://doorman.fyi/docs/reference/mail.md#threads-messages) answers the thread and its messages, oldest first, at most 500. [`GET /v1/inboxes/{inboxId}/messages`](https://doorman.fyi/docs/reference/mail.md#inboxes-messages-list) lists an inbox's messages across threads, newest first, with `direction=inbound` or `outbound` to keep one side. [`GET /v1/messages/{messageId}`](https://doorman.fyi/docs/reference/mail.md#messages-get) reads one.

A [`Message`](https://doorman.fyi/docs/reference/schemas.md#Message) is one email with everything an agent needs and nothing it has to parse:

- Who and what: `from`, `to`, `cc` and `bcc` as address and display name pairs; `replyTo` when the sender set one; `subject`; `deliveryRole`, how the inbox received the message (as a `to`, `cc` or `bcc` recipient).
- The text: `text` is the plain-text body, or text derived from the HTML when there was none. `hasHtml` says whether an HTML body is stored.
- Threading headers: `rfcMessageId`, `inReplyTo` and `references`, as the message carried them.
- Classification: `category`, `verdict`, `autoReplyable` and `authentication` (the SPF, DKIM and DMARC results), explained below.
- Where the rest is: `rawUrl` for the original message, and `attachments` with their download URLs and extracted text.
- When: `occurredAt` is the instant the message arrived (or was sent). Arrival time orders a thread; the sender's `Date` header is not trusted to.

A message:
```json
{
  "id": "msg_01jc5a6g7h8j9k0m1n2p3q4r5s",
  "inboxId": "inb_01jc4q7w9k2m5n8p3r6t1v4x7z",
  "threadId": "thr_01jc5a1b2c3d4e5f6g7h8j9k0m",
  "direction": "inbound",
  "rfcMessageId": "<a1b2c3@example.com>",
  "inReplyTo": null,
  "references": [],
  "from": {
    "address": "sam@example.com",
    "name": "Sam Rivera"
  },
  "to": [
    {
      "address": "concierge@doorman.example",
      "name": null
    }
  ],
  "cc": [],
  "bcc": [],
  "replyTo": null,
  "deliveryRole": "to",
  "subject": "Invoice 2847",
  "text": "Hi, invoice 2847 is attached.",
  "hasHtml": true,
  "rawUrl": "https://api.doorman.example/v1/messages/msg_01jc5a6g7h8j9k0m1n2p3q4r5s/raw",
  "sizeBytes": 48120,
  "category": "personal",
  "autoReplyable": true,
  "verdict": "clean",
  "spamScore": 0.02,
  "authentication": {
    "spf": "pass",
    "dkim": "pass",
    "dmarc": "pass"
  },
  "risk": {
    "score": 6,
    "level": "low",
    "labels": [],
    "reasons": [],
    "sender": {
      "standing": "known",
      "authenticated": true
    },
    "action": "delivered",
    "analysis": "full",
    "review": null
  },
  "occurredAt": "2026-11-05T10:05:00.000Z",
  "attachments": [
    {
      "filename": "invoice.pdf",
      "contentType": "application/pdf",
      "sizeBytes": 45000,
      "url": "https://api.doorman.example/v1/attachments/msg_01jc5a6g7h8j9k0m1n2p3q4r5s/invoice.pdf",
      "parsedText": "Invoice 2847. Line 3: Setup fee, billed twice. Total 1,480.",
      "extractionMethod": "pdf"
    }
  ]
}
```

## Attachments and extracted text

Each attachment is stored as it arrived and listed on the message as an [`Attachment`](https://doorman.fyi/docs/reference/schemas.md#Attachment): `filename` (unique within the message), `contentType`, `sizeBytes`, `url` to download the bytes with the same credential as the API, `parsedText` when extraction produced any, and `extractionMethod`, which says how the text was obtained or why it was not.

An attachment of any type is accepted and stored. Assessed mail also carries `scan` on each attachment, an [`AttachmentScan`](https://doorman.fyi/docs/reference/schemas.md#AttachmentScan): what the bytes are whatever the file is called (`detectedType`), their `sha256`, a `status` of `clean`, `suspicious`, `malicious` or `unscanned`, and the `findings` behind it. Nothing is extracted from a `malicious` attachment, and a key or an app token cannot download one (`403 risk_blocked`). [Attachments and links](https://doorman.fyi/docs/security.md#files) explains each status.

The same text is in the webhook payload, so an agent reads an attached invoice in the very first event. [`GET /v1/attachments/{messageId}/{filename}/text`](https://doorman.fyi/docs/reference/mail.md#attachments-text) answers the text on its own, and [`GET /v1/attachments/{messageId}/{filename}`](https://doorman.fyi/docs/reference/mail.md#attachments-download) the bytes.

| Method | Meaning |
| --- | --- |
| `text` | Plain text, Markdown, JSON, XML, YAML, logs and calendars: decoded as text. |
| `csv` | CSV and tab-separated files. |
| `pdf` | PDF documents, read into text by the platform's document converter. |
| `ocr` | PNG, JPEG, WebP, GIF and SVG images, read by the converter. |
| `office` | Word, Excel, PowerPoint, OpenDocument and Numbers files, read by the converter. |
| `unsupported` | A type nothing reads, such as a binary or an archive. |
| `skipped` | Beyond the first 10 attachments of a message, which are stored but not read. |
| `skipped_too_large` | Larger than 10 MiB. |
| `unavailable` | The converter is not configured on this deployment, so only text, CSV and HTML are read. |
| `timeout`, `pdf_error`, `ocr_error`, `office_error`, `html_error` | Extraction was attempted and did not finish; the bytes are still there. |

Extracted text is capped at 50,000 characters. The complete list of methods is `text`, `csv`, `pdf`, `ocr`, `office`, `unsupported`, `skipped`, `skipped_too_large`, `unavailable`, `timeout`, `pdf_error`, `ocr_error`, `office_error`, `html_error`.

## The raw and HTML bodies

[`GET /v1/messages/{messageId}/raw`](https://doorman.fyi/docs/reference/mail.md#messages-raw) downloads the original message as `message/rfc822`, every header and part included, for anything the parsed form leaves out. Outbound messages have no raw copy and answer `404`.

[`GET /v1/messages/{messageId}/html`](https://doorman.fyi/docs/reference/mail.md#messages-html) serves the stored HTML body as `text/html` under `cache-control: private, no-store`, `x-content-type-options: nosniff` and a content security policy that allows images and inline styles only, with `sandbox`. Show it in a sandboxed frame rather than inside your own page. `404` when the message has no HTML body.

## Categories, verdicts and the auto-replyable flag

Every inbound message is classified at the door from its headers, so an agent knows what not to answer. `category` is one of `personal`, `automated`, `marketing`, `bounce`, `spam`, `malicious`:

- `bounce`: An empty envelope sender, a sender such as `mailer-daemon` or `postmaster`, a `multipart/report` body, or an `X-Failed-Recipients` header.
- `spam`: The platform's `X-Spam-Flag` or `X-Spam-Status` says yes.
- `marketing`: A `List-Unsubscribe` header, or `Precedence: bulk` with a `List-Id` or `Feedback-ID`.
- `automated`: `Auto-Submitted` (other than `no`), `Precedence` bulk, list, junk or auto_reply, a `List-Id`, an auto-response suppression header, or an automated-looking sender such as `no-reply`, `notifications`, `alerts`, `mailer`, `system`, `robot` or `bot`.
- `personal`: Everything else: mail a person wrote. Outbound messages are always `personal`.
- `malicious`: Assigned in `enforce` mode when Doorman's inbound risk assessment rates a non-spam threat critical or detects disguised malware. See [Security and sender trust](https://doorman.fyi/docs/security.md).

`verdict` comes from the first `Authentication-Results` header, which is trusted only when the mail platform wrote it: `clean`, `unverified`, `suspicious`. DMARC pass is `clean`, DMARC fail is `suspicious`, and without a DMARC result a DKIM or SPF pass is `clean` and anything else `unverified`. A message with no trusted results is `unverified`; an outbound message has a null verdict.

`autoReplyable` (`auto_replyable` in the webhook payload) is true only for a `personal` message whose verdict is not `suspicious` and, where security policies are enforced, that was neither warned about, held nor rated high risk. An agent that answers on its own should check it first: it keeps the agent out of bounce loops, off mailing lists and away from spoofed or flagged mail.

> Note: In addition to header classification, assessed inbound mail carries `risk` (`RiskAssessment`) and `spamScore` (0 to 1); see [Security and sender trust](https://doorman.fyi/docs/security.md).

## How messages join a thread

- A message whose `In-Reply-To` or `References` names a message the inbox already holds joins that message's thread. Both the original `Message-ID` and the identifier the sending provider assigned to an outbound message are matched, so replies to mail the agent sent thread correctly.
- A message without a matching header joins the newest thread with the same normalized subject (reply and forward prefixes removed) when the sender already took part in it and the thread had activity within the last 14 days.
- Otherwise the message starts a new thread. A trashed thread is never reopened: a later message in the same conversation starts a new one, as a mail client would.

A thread's `participants` lists the addresses that took part in it, kept sorted; `q` on the thread list searches them. An inbound message marks its thread unread again.

## Duplicates

Mail servers retry. A message whose `Message-ID` the inbox already holds is accepted and dropped silently, so the same email never becomes two messages or two events. A message without a `Message-ID` cannot be deduplicated this way; it is stored each time it arrives.

Webhook delivery is at least once as well, for the same reason, and the event id in `webhook-id` is stable across retries: [deduplicate on it](https://doorman.fyi/docs/webhooks.md#retries).
