---
title: Gmail
icon: google
description: Mount a Gmail mailbox as a Mirage filesystem from Node or the browser.
---

`GmailResource` browses messages, threads, and labels via the Gmail API.

Both runtimes share the same OAuth config: a Google Cloud `clientId` / `clientSecret` plus a long-lived `refreshToken` for the user. Setup steps live at [Google Workspace Credentials](/home/setup/google).

## Node

```bash
pnpm add @struktoai/mirage-node
```

```ts
import { GmailResource, MountMode, Workspace } from '@struktoai/mirage-node'

const gmail = new GmailResource({
  clientId: process.env.GOOGLE_CLIENT_ID!,
  clientSecret: process.env.GOOGLE_CLIENT_SECRET!,
  refreshToken: process.env.GOOGLE_REFRESH_TOKEN!,
})

const ws = new Workspace({ '/mail': gmail }, { mode: MountMode.READ })
await ws.execute('ls /mail/INBOX/')
```

## Browser

```bash
pnpm add @struktoai/mirage-browser
```

```ts
import { GmailResource, MountMode, Workspace } from '@struktoai/mirage-browser'

const gmail = new GmailResource({
  clientId: GOOGLE_CLIENT_ID,
  clientSecret: GOOGLE_CLIENT_SECRET,
  refreshToken: localStorage.getItem('gmail.refresh_token')!,
})

const ws = new Workspace({ '/mail': gmail }, { mode: MountMode.READ })
```

For OAuth in a browser, prefer PKCE so secrets stay off the page; the [Google setup guide](/home/setup/google) shows the flow.

## Config

| Field | Default | Notes |
| --- | --- | --- |
| `clientId` | required | Google OAuth client ID. |
| `clientSecret` | required | Google OAuth client secret. Redacted in snapshots. |
| `refreshToken` | required | User's refresh token. Redacted in snapshots. |
| `refreshFn` | built-in | Optional override for the access-token refresh callback. |

## Mount mode

`read`. Partial write (drafts, labels) is exposed via Python and may land in TS in a future release.

For the mounted layout (labels, dates, attachments) see the [Python Gmail docs](/python/resource/gmail).
