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

# Service Account Setup

This section walks through setting up the Gmail connector using a Service Account.
More info on Service Accounts can be found [here](https://cloud.google.com/iam/docs/service-account-overview).
A Google Workspace is required.

If you'd rather use an individuals account + OAuth to access Gmail, checkout the section
[here](/connectors/gmail/oauth).

### Authorization

1. Create a **Google Cloud Project**
   * [https://console.cloud.google.com/projectcreate](https://console.cloud.google.com/projectcreate)

2. Enable the **Gmail API**
   * On the left panel, open **APIs & services**
   * Go to **Enabled APIs and services**
   * On the top click **+ENABLE APIS AND SERVICES**
   * Search for **Gmail API** and click **ENABLE**
   * Alternatively visit this [link](https://console.cloud.google.com/flows/enableapi?apiid=gmail.googleapis.com),
     select your project and enable the **Gmail API**

3. Enable the **Admin SDK API**
   * Click on **+ENABLE APIS AND SERVICES** again.
   * Search for **Admin SDK API** and click **ENABLE**
   * Alternatively visit this [link](https://console.cloud.google.com/flows/enableapi?apiid=admin.googleapis.com),
     select your project and enable the **Admin SDK API**

<img src="https://mintcdn.com/utopikai/fX4Gfjw1E606KuQ9/images/connectors/google_drive/GoogleDriveEnableAPI.png?fit=max&auto=format&n=fX4Gfjw1E606KuQ9&q=85&s=04d38ed338e13a4c33c0a1d083daa77a" alt="GoogleDriveEnableAPI" width="808" height="497" data-path="images/connectors/google_drive/GoogleDriveEnableAPI.png" />

4. Create a **Service Account**

   * Go to the [Service Account management page](https://console.cloud.google.com/iam-admin/serviceaccounts)
     in Google Cloud.
   * Click `Create Service Account` button and fill out the fields in step 1. You can ignore steps 2 and 3.
   * Go to the `Keys` section, and click `Add Key`. Download this key, you will need to upload to to UtopikAI
     later.

   Note for Google Organizations created after April 2024:

   * to give the service account the proper permissions you will have to navigate to this [link](https://console.cloud.google.com/iam-admin/orgpolicies/iam-disableServiceAccountKeyCreation)
   * Then select `Manage`, select `Override parent's policy` and then select `Not enforced` under `Rules`.
   * Finally, select `SET POLICY`

<iframe width="840" height="473" src="https://www.youtube.com/embed/Z5R9HUCVVAE?si=GZxteF6rmIHa1BOE" title="YouTube video player" frameBorder="0" allow="accelerometer; autoplay; clipboard-write; encrypted-media; gyroscope; picture-in-picture; web-share; fullscreen;" allowfullscreen />

5. Give this **Service Account** read-only access to Gmail
   * Copy the `Unique ID` of the Service Account
   * Go to the [Domain-wide Delegation page](https://admin.google.com/u/3/ac/owl/domainwidedelegation) in the Google Admin Console.
   * Click `Add new`, fill in the client ID with the `Unique ID` of the Service account
   * Copy this comma separated list of scopes and pasted it into field `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`
