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

# Gmail Service Account

> Set up Gmail Service Account for the connector

This guide sets up the Gmail connector with a Google service account. A Google Workspace is required.

If you prefer to sign in with one Google account, follow the [OAuth guide](https://docs.onyx.app/admins/connectors/official/gmail/oauth.md).

### Authorization

**1. Create a Google Cloud project**

Go to [https://console.cloud.google.com/projectcreate](https://console.cloud.google.com/projectcreate)
and create a project.

**2. Enable the Gmail API and the Admin SDK API**

* In the left panel, open **APIs & services** and go to **Enabled APIs and services**.
* Click **+ ENABLE APIS AND SERVICES**.
* Search for **Gmail API** and click **ENABLE**.
* Search for **Admin SDK API** and click **ENABLE**.

![Google Cloud Console enabling APIs for the project](https://mintcdn.com/danswer/jgw6Cs2MHeFwiQG_/assets/admins/connectors/google_drive/GoogleDriveEnableAPI.webp?fit=max\&auto=format\&n=jgw6Cs2MHeFwiQG_\&q=85\&s=e0882f595fb252e8bdb3965aab04be2a)

**3. Create a service account**

* Open the [service accounts page](https://console.cloud.google.com/iam-admin/serviceaccounts) in Google Cloud.
* Click **Create Service Account** and complete step 1. Skip steps 2 and 3.
* Open the **Keys** section and click **Add Key**. Download the JSON key.

For Google organizations created after April 2024, allow key creation first:

* Open this [policy page](https://console.cloud.google.com/iam-admin/orgpolicies/iam-disableServiceAccountKeyCreation).
* Select **Manage**, then **Override parent's policy**, then **Not enforced** under **Rules**.
* Select **SET POLICY**.

[YouTube video
player](https://www.youtube.com/embed/Z5R9HUCVVAE?si=GZxteF6rmIHa1BOE)

**4. Grant domain-wide delegation**

Give the service account read-only access to Gmail:

* Copy the **Unique ID** of the service account.
* Open the [Domain-wide Delegation page](https://admin.google.com/ac/owl/domainwidedelegation) in the Google Admin
  console.
* Click **Add new** and enter the **Unique ID** as the client ID.
* Paste this list into **OAuth scopes**:
  `https://www.googleapis.com/auth/gmail.readonly,https://www.googleapis.com/auth/admin.directory.group.readonly,https://www.googleapis.com/auth/admin.directory.user.readonly`

### Indexing

**1. Create the account**

In the Onyx admin panel, go to **Connectors** and select **Gmail**. Under **Authentication Account**,
click **Create New** and select **Service Account**.

* **Primary Admin Email**: the email of a user with an admin role in the Google Workspace that has the
  **Users > Read** and **Groups > Read** privileges. This can be an existing admin or an account created for Onyx,
  such as `onyx-robot@your-domain.com`. Do not enter the service account email.
  Set the role in the Google Admin console under **Account > Admin roles**.
* **Service Account Key**: upload or paste the JSON key you downloaded.

**2. Choose document access**

Under **Document Access**, select who can see the indexed threads.
**Sync with Gmail** mirrors each user's own mailbox.
**Specific Groups** and **Sync with Gmail** are available on the Business and Enterprise plans and on Onyx Cloud.
Then click **Create Connector**.

> [!NOTE]
>
> You can create more than one Gmail account on a single Onyx instance, each with its own service account.
> This lets you index multiple Google Workspaces from one Onyx deployment.
> Create a separate account and connector for each workspace.

> [!NOTE]
>
> A Google account is listed on both the Gmail and the Google Drive connector forms.
> To use one service account for both connectors, delegate the scopes of both:
> `https://www.googleapis.com/auth/gmail.readonly,https://www.googleapis.com/auth/drive.readonly,https://www.googleapis.com/auth/drive.metadata.readonly,https://www.googleapis.com/auth/admin.directory.group.readonly,https://www.googleapis.com/auth/admin.directory.user.readonly`.
> With only one connector's scopes delegated, the account works for that connector only.


This documentation is built and hosted on [Mintlify](https://mintlify.com), a developer documentation platform.