# Gmail

Source: https://docs.autessa.com/docs/tools/gmail

> Tool types for reading, searching, drafting, and sending mail through a connected Gmail account.

# Gmail

Give agents a real Gmail mailbox: list and search messages, read full bodies and attachments, manage labels, and draft or send mail as the connected account.

Every tool type on this page requires a **Gmail connector** — an OAuth connection to the Google account whose mailbox the agent should work in. The tool config points at the connector with `connectorId`, and Autessa refreshes the OAuth token automatically before each call. See [Connectors](/docs/guide/connectors.md) for how to link an account.

Reading tools return decoded message bodies (not just snippets), so agents can act on full email content without extra round-trips.

## List Unread **TOOL** `GMAIL_LIST_UNREAD`

Lists unread messages in the mailbox, optionally narrowed to specific label IDs, and fetches each result in full. The response contains `totalResults` plus a `messages` array where every entry carries `id`, `threadId`, the key headers (From, To, Subject, Date, Cc, Bcc, Reply-To, Message-ID), the `snippet`, and the decoded plain-text `body`. If an unread message already has a draft reply in progress, its `draftId` is included so the agent can update the existing draft instead of creating a duplicate. `maxResults` defaults to 10 when unset.

### Example

```json title="Tool config"
{
  "toolType": "GMAIL_LIST_UNREAD",
  "connectorId": "V1StGXR8Z5",
  "maxResults": 25,
  "includeSpamTrash": false,
  "labelIds": ["INBOX"]
}
```

> This tool type requires a connected external account. Pass the connector's ID as `connectorId` in the tool configuration.

**Configuration fields**

- `connectorId` (string (ID)) — Required string (ID) value. References a connector by ID.
- `maxResults` (integer) — Required integer value.
- `includeSpamTrash` (boolean) — Required boolean value.
- `labelIds` (array<string> · optional) — Optional filter

## Mark as Read **TOOL** `GMAIL_MARK_AS_READ`

Removes the `UNREAD` label from a single message, marking it read in the connected mailbox. Agents typically call this after processing a message surfaced by List Unread so the same email is not handled twice. The result confirms the `messageId` that was updated; no other labels are touched.

### Example

```json title="Tool config"
{
  "toolType": "GMAIL_MARK_AS_READ",
  "connectorId": "V1StGXR8Z5",
  "messageId": "@@{messageId}"
}
```

> This tool type requires a connected external account. Pass the connector's ID as `connectorId` in the tool configuration.

**Configuration fields**

- `connectorId` (string (ID)) — Required string (ID) value. References a connector by ID.
- `messageId` (string) — Required string value.

## Move to Label **TOOL** `GMAIL_MOVE_TO_LABEL`

Modifies the labels on a message in one call: every ID in `addLabelIds` is applied and every ID in `removeLabelIds` is stripped. Because Gmail folders are just labels, this is also how an agent archives or files mail — removing `INBOX` while adding a custom label moves the message out of the inbox and into that label. The result echoes the `addedLabels` and `removedLabels` that were applied.

### Example

```json title="Tool config"
{
  "toolType": "GMAIL_MOVE_TO_LABEL",
  "connectorId": "V1StGXR8Z5",
  "messageId": "@@{messageId}",
  "addLabelIds": ["Label_1234567890"],
  "removeLabelIds": ["INBOX"]
}
```

> This tool type requires a connected external account. Pass the connector's ID as `connectorId` in the tool configuration.

**Configuration fields**

- `connectorId` (string (ID)) — Required string (ID) value. References a connector by ID.
- `messageId` (string) — Required string value.
- `addLabelIds` (array<string>) — Required array<string> value.
- `removeLabelIds` (array<string>) — Required array<string> value.

## Create Draft Reply **TOOL** `GMAIL_CREATE_DRAFT_REPLY`

Drafts a threaded reply to an existing message: the executor reads the original's headers, sets `In-Reply-To` and `References` so the reply lands in the same conversation, prefixes the subject with `Re:`, and addresses the original sender — with `replyAll` unset or true, the original To and Cc recipients are included too (the connected account's own address is always filtered out). If the thread already ends in a draft, that draft is updated in place rather than duplicated, and the result carries `updated: true`. The result includes the `draftId`, `threadId`, and resolved recipient lists; at least one of `replyBody` or `replyBodyHtml` must be provided, and nothing is sent until a Send Draft call.

### Example

```json title="Tool config"
{
  "toolType": "GMAIL_CREATE_DRAFT_REPLY",
  "connectorId": "V1StGXR8Z5",
  "originalMessageId": "@@{messageId}",
  "replyBody": "@@{replyText}",
  "replyAll": true
}
```

> This tool type requires a connected external account. Pass the connector's ID as `connectorId` in the tool configuration.

**Configuration fields**

- `connectorId` (string (ID)) — Required string (ID) value. References a connector by ID.
- `originalMessageId` (string) — Required string value.
- `replyBody` (string) — Required string value.
- `replyBodyHtml` (string · optional) — Optional
- `replyAll` (boolean · optional) — Optional; null is treated as true (reply all)
- `attachments` (array<object> · optional) — Optional; re-uploaded in full when the draft is updated
- `fromName` (string · optional) — Optional

## Create Draft **TOOL** `GMAIL_CREATE_DRAFT`

Creates a fresh draft (not attached to any thread) addressed from the connected account. Supply plain text in `body`, HTML in `bodyHtml`, or both — when HTML is present the draft is built as a `multipart/alternative` message so recipients without HTML rendering still see the text part; at least one of the two body fields is required. The result returns the `draftId` to pass to Send Draft, and the draft sits in the user's Gmail Drafts folder for human review before anything goes out.

### Example

```json title="Tool config"
{
  "toolType": "GMAIL_CREATE_DRAFT",
  "connectorId": "V1StGXR8Z5",
  "to": "@@{recipientEmail}",
  "subject": "Your onboarding checklist",
  "body": "@@{draftText}",
  "cc": "success@acme.example"
}
```

> This tool type requires a connected external account. Pass the connector's ID as `connectorId` in the tool configuration.

**Configuration fields**

- `connectorId` (string (ID)) — Required string (ID) value. References a connector by ID.
- `to` (string) — Required string value.
- `subject` (string) — Required string value.
- `body` (string) — Required string value.
- `bodyHtml` (string · optional) — Optional
- `cc` (string · optional) — Optional
- `bcc` (string · optional) — Optional
- `attachments` (array<object> · optional) — Optional
- `fromName` (string · optional) — Optional

## Send Draft **TOOL** `GMAIL_SEND_DRAFT`

Sends an existing draft by its `draftId` — the counterpart to Create Draft and Create Draft Reply in a review-then-send workflow. Gmail delivers the draft exactly as it stands (including any human edits made in the meantime) and removes it from the Drafts folder. The result returns the sent message's `messageId` and `threadId`.

### Example

```json title="Tool config"
{
  "toolType": "GMAIL_SEND_DRAFT",
  "connectorId": "V1StGXR8Z5",
  "draftId": "@@{draftId}"
}
```

> This tool type requires a connected external account. Pass the connector's ID as `connectorId` in the tool configuration.

**Configuration fields**

- `connectorId` (string (ID)) — Required string (ID) value. References a connector by ID.
- `draftId` (string) — Required string value.

## Send Email **TOOL** `GMAIL_SEND_EMAIL`

Sends a message immediately from the connected account, with no draft step and no human checkpoint — reserve it for agents trusted to send autonomously, and prefer the draft tools when a review step is wanted. Like Create Draft it accepts `body`, `bodyHtml`, or both (sent as `multipart/alternative`), plus optional `cc` and `bcc`. The result returns the new `messageId` and `threadId`.

### Example

```json title="Tool config"
{
  "toolType": "GMAIL_SEND_EMAIL",
  "connectorId": "V1StGXR8Z5",
  "to": "@@{recipientEmail}",
  "subject": "@@{subject}",
  "body": "@@{messageText}"
}
```

> This tool type requires a connected external account. Pass the connector's ID as `connectorId` in the tool configuration.

**Configuration fields**

- `connectorId` (string (ID)) — Required string (ID) value. References a connector by ID.
- `to` (string) — Required string value.
- `subject` (string) — Required string value.
- `body` (string) — Required string value.
- `bodyHtml` (string · optional) — Optional
- `cc` (string · optional) — Optional
- `bcc` (string · optional) — Optional
- `attachments` (array<object> · optional) — Optional
- `fromName` (string · optional) — Optional

## Get Message by ID **TOOL** `GMAIL_GET_MESSAGE_BY_ID`

Fetches one message in full and returns an `email` object with headers, `labelIds`, `snippet`, `internalDate`, `sizeEstimate`, and the decoded `body` (plain text preferred, falling back to HTML). It is also the richest way to reach attachments: each attachment is downloaded, staged, and listed with `fileName`, `mimeType`, `attachmentId`, and ready-to-use `url` and `downloadUrl` links that expire after 15 minutes. Use it after a list or search call when the agent needs the complete content of a specific message.

### Example

```json title="Tool config"
{
  "toolType": "GMAIL_GET_MESSAGE_BY_ID",
  "connectorId": "V1StGXR8Z5",
  "messageId": "@@{messageId}"
}
```

> This tool type requires a connected external account. Pass the connector's ID as `connectorId` in the tool configuration.

**Configuration fields**

- `connectorId` (string (ID)) — Required string (ID) value. References a connector by ID.
- `messageId` (string) — Required string value.

## Get Attachment Content **TOOL** `GMAIL_GET_ATTACHMENT_CONTENT`

Downloads a single attachment and runs it through Autessa's file-content extraction, returning the attachment's text content directly in the result (`fileName`, `mimeType`, `content`) — not a link and not base64. This lets an agent read a PDF invoice or Word document from an email in one step. Use the `attachmentId` values surfaced by Get Message by ID or Search Messages; if the file's content cannot be extracted the tool fails with `EXTRACTION_FAILED` rather than returning raw bytes.

### Example

```json title="Tool config"
{
  "toolType": "GMAIL_GET_ATTACHMENT_CONTENT",
  "connectorId": "V1StGXR8Z5",
  "messageId": "@@{messageId}",
  "attachmentId": "@@{attachmentId}"
}
```

> This tool type requires a connected external account. Pass the connector's ID as `connectorId` in the tool configuration.

**Configuration fields**

- `connectorId` (string (ID)) — Required string (ID) value. References a connector by ID.
- `messageId` (string) — Required string value.
- `attachmentId` (string) — Required string value.

## Get Attachment Download Link **TOOL** `GMAIL_GET_ATTACHMENT_DOWNLOAD_LINK`

Downloads an attachment, stages it, and returns links instead of content: a short `downloadUrl` on the Autessa domain plus the underlying `presignedUrl`, both valid for 15 minutes (`expiresInSeconds: 900`). The result also reports `fileName`, `mimeType`, and `fileSizeBytes`. Use this when the file should be handed to a person or another tool rather than read as text.

To keep the file instead, set `saveToTableId` and `saveToColumnName`: the attachment is stored as a file in that AutessaDB table's FILE, IMAGE, VIDEO or AUDIO column, and the result returns its `s3Uri` (write it into that column's `filePath` on insert or update) along with `fileName`, `mimeType`, `fileSizeBytes`, `columnName`, `columnType` and `opaque`. The column must accept the file's type, exactly as for an upload link; a FILE column also accepts any other type, stored unchanged and always served as a download (`opaque: true`). This is how a script — which cannot move file bytes itself — files email attachments into a table. Attachments up to 200 MB.

### Example

```json title="Tool config"
{
  "toolType": "GMAIL_GET_ATTACHMENT_DOWNLOAD_LINK",
  "connectorId": "V1StGXR8Z5",
  "messageId": "@@{messageId}",
  "attachmentId": "@@{attachmentId}"
}
```

```json title="Tool config — save into a table"
{
  "toolType": "GMAIL_GET_ATTACHMENT_DOWNLOAD_LINK",
  "connectorId": "V1StGXR8Z5",
  "messageId": "@@{messageId}",
  "attachmentId": "@@{attachmentId}",
  "saveToTableId": "Xk9Pq2LmTz4R",
  "saveToColumnName": "@@{column}"
}
```

> This tool type requires a connected external account. Pass the connector's ID as `connectorId` in the tool configuration.

**Configuration fields**

- `connectorId` (string (ID)) — Required string (ID) value. References a connector by ID.
- `messageId` (string) — Required string value.
- `attachmentId` (string) — Required string value.
- `saveToTableId` (string (ID) · optional) — Optional: store the attachment as a file in this AutessaDB table (same company) instead of returning it; the result's `s3Uri` is what to write into that column's filePath. Lets a script (which has no IO) put email attachments into a table. Set together with saveToColumnName. References an AutessaDB table by ID.
- `saveToColumnName` (string · optional) — Optional (required with saveToTableId): the FILE, IMAGE, VIDEO or AUDIO column the file is stored for. It must accept the file's type; a FILE column takes any type.

## Search Messages **TOOL** `GMAIL_SEARCH_MESSAGES`

Searches the mailbox by combining the structured fields into a single Gmail query — `from`, `to`, and `subject` become their matching operators, `hasAttachment` adds `has:attachment`, `after`/`before` add date bounds, `labelIds`, `isUnread`, and `isStarred` add their filters, and anything in `query` is appended as free-form Gmail search syntax (so `query` alone can express any search Gmail supports). Each hit is returned in full: headers, `labelIds`, `snippet`, `internalDate`, the decoded `body`, and attachment metadata (`fileName`, `mimeType`, `attachmentId` — no download links; follow up with the attachment tools). `maxResults` defaults to 10.

### Example

```json title="Tool config"
{
  "toolType": "GMAIL_SEARCH_MESSAGES",
  "connectorId": "V1StGXR8Z5",
  "from": "@@{senderEmail}",
  "query": "invoice",
  "hasAttachment": true,
  "after": "2026/06/01",
  "isUnread": true,
  "maxResults": 20
}
```

> This tool type requires a connected external account. Pass the connector's ID as `connectorId` in the tool configuration.

**Configuration fields**

- `connectorId` (string (ID)) — Required string (ID) value. References a connector by ID.
- `from` (string) — Required string value.
- `to` (string) — Required string value.
- `subject` (string) — Required string value.
- `query` (string) — Required string value.
- `hasAttachment` (boolean) — Required boolean value.
- `after` (string) — Required string value.
- `before` (string) — Required string value.
- `labelIds` (array<string>) — Required array<string> value.
- `isUnread` (boolean) — Required boolean value.
- `isStarred` (boolean) — Required boolean value.
- `maxResults` (integer) — Required integer value.
- `includeSpamTrash` (boolean) — Required boolean value.

## Related

- [Connectors](/docs/guide/connectors.md)
- [Outlook Mail tool types](/docs/tools/outlook-mail.md)
- [Calendar tool types](/docs/tools/calendars.md)
- [Email tool types](/docs/tools/email.md)
- [Tools in the agentic guide](/docs/guide/agentic/tools.md)

