> ## 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.

# On message deleted

> Run an automation when Gmail permanently deletes a message.

`gmail.onMessageDeleted` handles permanent Gmail message deletion. Moving a message to Trash doesn't qualify.

## Example

```ts automations/record-deleted-message.automation.ts theme={null}
import { automation } from "automate.ax"
import { gmail } from "automate.ax/gmail"

export default automation("Record deleted Gmail messages", () => {
  const deletion = gmail.onMessageDeleted()

  // Remove the deleted Gmail message from the CRM.
})
```

## Options

`account` is a static Google Account binding and defaults to the project binding. It can't change at runtime.

## Trigger data

```ts theme={null}
interface GmailMessageDeleted {
  historyId: string
  messageId: string
  threadId: string
}
```

Gmail reports only stable identifiers after permanent deletion because the message resource is no longer available. `historyId` identifies the mailbox history record that reported the lifecycle.
