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

# Email

> Cloud API endpoints for Gmail OAuth and webhook integration.

All endpoints require authentication. See [Authentication](/cloud/authentication).

## Start OAuth flow

```bash theme={null}
GET /api/email/oauth/authorize
```

Redirects the user to Google's OAuth consent screen. After authorization, Google redirects back to the callback URL.

## OAuth callback

```bash theme={null}
GET /api/email/oauth/callback
```

Handles the OAuth redirect from Google, exchanges the authorization code for tokens, and stores them securely.

## Get OAuth tokens

```bash theme={null}
GET /api/email/oauth/tokens
```

Returns the stored OAuth token metadata for the team (not the raw tokens). Used by the service in remote mode to fetch emails.

## Revoke OAuth access

```bash theme={null}
POST /api/email/oauth/revoke
```

Revokes the Gmail OAuth tokens and removes the stored credentials.

## Gmail webhook

```bash theme={null}
POST /api/email/webhook
```

Receives push notifications from Google Cloud Pub/Sub when new emails arrive. This endpoint is called by Google, not by users directly.

The webhook:

1. Validates the Pub/Sub message
2. Queues an event in the `event_queue` table
3. The service picks up the event via the SSE stream at `GET /api/events/stream`
