> ## 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 / Gmail

> Process Gmail messages using OAuth and Google Cloud Pub/Sub push notifications.

OpenBunny processes Gmail messages using the Gmail API with OAuth authentication and Google Cloud Pub/Sub for real-time push notifications.

## Prerequisites

* A Google Cloud project with the Gmail API enabled
* A Pub/Sub topic configured for Gmail push notifications
* OAuth 2.0 credentials (client ID and secret)

## Setup

<Steps>
  ### Create Google Cloud credentials

  1. Go to the [Google Cloud Console](https://console.cloud.google.com)
  2. Enable the **Gmail API**
  3. Create OAuth 2.0 credentials (Web application type)
  4. Add your redirect URI (cloud URL + `/api/email/oauth/callback`)

  ### Set up Pub/Sub

  1. Create a Pub/Sub topic for Gmail notifications
  2. Grant the Gmail service account (`gmail-api-push@system.gserviceaccount.com`) publish access to the topic
  3. Create a subscription that pushes to your cloud webhook endpoint

  ### Configure environment

  ```bash .env theme={null}
  GOOGLE_CLIENT_ID=your-client-id
  GOOGLE_CLIENT_SECRET=your-client-secret
  GOOGLE_PUBSUB_TOPIC=projects/your-project/topics/gmail-notifications
  ```

  ### Authorize Gmail

  In the cloud web UI, go to **Settings > Email** and click **Connect Gmail**. This initiates the OAuth flow and stores tokens securely.
</Steps>

## How it works

1. Gmail sends push notifications to the Pub/Sub topic when new emails arrive
2. The cloud receives the webhook and queues an event
3. The service picks up the event via SSE stream
4. The service fetches the email content via the Gmail API
5. The email is processed through the standard LLM agent pipeline

<Note>
  Gmail integration requires the cloud component even in hybrid mode, since OAuth tokens and webhooks are managed through the cloud API.
</Note>
