> ## Documentation Index
> Fetch the complete documentation index at: https://docs.automate.ax/llms.txt
> Use this file to discover all available pages before exploring further.

> ## Agent Instructions
> Automate.ax automations are TypeScript programs.
> Use Bun for installation and command examples.
> Use Automate.ax for the product name and automate.ax for the package, CLI, and domain.
> Treat documented public APIs as current; do not invent transitional or deprecated names.

# Get a draft

> Retrieve a Gmail draft with its parsed message, headers, bodies, and attachments.

`getDraft` retrieves one Gmail draft and fully parses the message stored inside
it. Use it when you need to inspect a draft before updating, sending, or
presenting it for review.

## Example

```ts automations/load-draft.automation.ts theme={null}
import { automation, onHttpRequest } from "automate.ax"
import { getDraft } from "automate.ax/gmail"

export default automation("Load a Gmail draft", () => {
  onHttpRequest({ scope: "automation" })

  getDraft({
    draftId: "r1234567890",
  })
})
```

## Inputs

| Input     | Type                                              | Required | Default         | Description                                   |
| --------- | ------------------------------------------------- | -------- | --------------- | --------------------------------------------- |
| `draftId` | `string`                                          | Yes      | —               | Immutable Gmail draft ID.                     |
| `account` | `string \| IntegrationAccountReference<"google">` | No       | Project default | Connected Google account that owns the draft. |

Every input, including `account`, also accepts a compatible `Signal`.

Pass the `draftId` returned by `draftEmail`, `draftReply`, `searchDrafts`, or
`updateDraft`. A draft's `messageId` is not accepted here. The action fails if
Gmail returns an incomplete draft or message.

## Output

The action returns a `Signal<Draft>` with:

| Property  | Type           | Description                                   |
| --------- | -------------- | --------------------------------------------- |
| `draftId` | `string`       | Immutable Gmail draft ID.                     |
| `message` | `GmailMessage` | Fully parsed message stored inside the draft. |

### Message

| Property          | Type                   | Description                                                                  |
| ----------------- | ---------------------- | ---------------------------------------------------------------------------- |
| `messageId`       | `string`               | Immutable Gmail message ID.                                                  |
| `threadId`        | `string`               | Immutable Gmail thread ID containing the draft.                              |
| `historyId`       | `string \| undefined`  | Latest mailbox history record affecting the message, when supplied.          |
| `labelIds`        | `string[]`             | Gmail system and user label IDs applied to the message.                      |
| `subject`         | `string`               | Decoded message subject. Empty when the draft has no subject.                |
| `text`            | `string \| undefined`  | Plain-text body, derived from HTML when no text alternative exists.          |
| `html`            | `string \| undefined`  | HTML body, when present.                                                     |
| `from`            | `Mailbox \| undefined` | Parsed From address.                                                         |
| `sender`          | `Mailbox \| undefined` | Sender header when distinct from From.                                       |
| `to`              | `Mailbox[]`            | Primary recipients.                                                          |
| `cc`              | `Mailbox[]`            | Carbon-copy recipients.                                                      |
| `bcc`             | `Mailbox[]`            | Blind-copy recipients retained in the raw draft, when available.             |
| `replyTo`         | `Mailbox[]`            | Addresses from the Reply-To header.                                          |
| `deliveredTo`     | `string \| undefined`  | Address recorded by Delivered-To.                                            |
| `returnPath`      | `string \| undefined`  | Address recorded by Return-Path.                                             |
| `headers`         | `MessageHeader[]`      | Decoded RFC 5322 headers with duplicates and original name casing preserved. |
| `rfc822MessageId` | `string \| undefined`  | RFC 5322 Message-ID from the message headers.                                |
| `inReplyTo`       | `string \| undefined`  | RFC Message-ID of the message this draft replies to.                         |
| `references`      | `string[]`             | RFC Message-IDs in the conversation ancestry.                                |
| `receivedAt`      | `Date \| null`         | Gmail mailbox time; `null` when Gmail supplies none.                         |
| `sentAt`          | `Date \| undefined`    | Date from the message headers when valid.                                    |
| `sizeEstimate`    | `number \| undefined`  | Estimated raw message size in bytes.                                         |
| `snippet`         | `string \| undefined`  | Short preview generated by Gmail.                                            |
| `attachments`     | `GmailAttachment[]`    | Parsed attachments and inline MIME parts.                                    |

`Mailbox` is `{ address: string; name?: string }`. `MessageHeader` is
`{ name: string; value: string }`.

Each `GmailAttachment` contains:

| Property      | Type                                    | Description                                                 |
| ------------- | --------------------------------------- | ----------------------------------------------------------- |
| `file`        | `File`                                  | Parsed attachment contents and metadata.                    |
| `filename`    | `string`                                | Filename presented by the sender.                           |
| `mimeType`    | `string`                                | MIME media type.                                            |
| `disposition` | `"attachment" \| "inline" \| undefined` | How the MIME part is presented.                             |
| `contentId`   | `string \| undefined`                   | Content-ID referenced by related HTML.                      |
| `description` | `string \| undefined`                   | Human-readable MIME description, when present.              |
| `related`     | `boolean`                               | Whether the attachment belongs to a multipart/related body. |
