B6AIDocs

Connect Gmail to B6AI

Set up the Gmail integration end to end, from creating credentials in Gmail to verifying the live connection and using it in your bots.

8 min read

Overview

The Gmail integration connects a Gmail or Google Workspace mailbox so bots and workflows can triage inbound email, draft and send replies, and apply labels for routing.

It turns a shared inbox (like support@yourco.com) into an automated first line that classifies, responds to, and organizes email.

What you will need
A Gmail account with administrator access, and a B6AI user with the Enterprise Admin role, integrations are configured once at the workspace level and shared by every bot.

What you can do with Gmail

Once connected, your bots and agents can use Gmail inside conversations and automations. Typical uses include:

  1. Read new inbound emails and classify them (for example by intent or priority).
  2. Send replies on behalf of the connected mailbox.
  3. Apply or remove labels to route messages or mark them handled.
  4. Create drafts for an agent to review before sending.
  5. Extract details from an email (order number, account id) to drive a flow.

How the integration works

B6AI uses Google OAuth 2.0. You create OAuth credentials in Google Cloud, grant the Gmail scopes, and authorize the specific mailbox in a consent popup.

B6AI stores the resulting refresh token (encrypted) and calls the Gmail API server-side. The connection is limited to exactly the scopes you approve.

Prerequisites

Make sure all of the following are in place before you start. Each one is required, skipping any will cause the connection to fail later.

  1. A Gmail or Google Workspace account with the mailbox you want to connect.
  2. Access to Google Cloud Console to create a project and an OAuth client.
  3. Permission to configure the OAuth consent screen for that project.
  4. The Enterprise Admin role in B6AI.

Create or prepare your Gmail account

Gmail access is granted through a Google Cloud project that owns the OAuth credentials.

  1. Go to console.cloud.google.com and create a new project (or pick an existing one).
  2. Open APIs & Services → Library, search for “Gmail API”, and click Enable.

Choose a connection method

B6AI supports more than one way to connect Gmail. Pick the one that fits your organization’s policies, the rest of this guide works for either.

MethodWhen to use itNotes
Standard OAuth (recommended)Connecting a single shared mailboxAuthorize the mailbox once via the consent popup; B6AI stores the refresh token.
Workspace domain-wide delegationAccessing many mailboxes across a Google WorkspaceA Workspace admin configures a service account with domain-wide delegation for the required scopes.

Generate your Google OAuth 2.0 credentials (Client ID & Secret)

B6AI authenticates with Gmail using your Google OAuth 2.0 credentials (Client ID & Secret). Follow these steps exactly, each field you copy here is entered into B6AI later.

  1. In Google Cloud Console, open APIs & Services → OAuth consent screen. Choose Internal (Workspace) or External, set an app name and support email, add the Gmail scopes below, and (if External while testing) add your mailbox as a Test user.
  2. Open APIs & Services → Credentials → Create credentials → OAuth client ID → Application type: Web application.
  3. Under Authorized redirect URIs, add the B6AI redirect URL shown below.
  4. Click Create and copy the Client ID and Client secret.
text
https://app.b6ai.ai/integrations/gmail/callback
Keep secrets safe
Treat every token, key and secret like a password. Never commit them to source control, paste them into chat, or email them. B6AI stores them encrypted at rest, enter them only in the integration settings.

The B6AI redirect / callback URL

During credential setup, Gmail asks for an authorized redirect (callback) URL. This is where Gmail returns you after you approve access. Use the exact URL below, a mismatch is the most common cause of a failed connection.

text
https://app.b6ai.ai/integrations/gmail/callback
Why this matters
OAuth providers reject the sign-in if the redirect URL does not match one you registered, character for character (including https and any trailing path). Copy it exactly.

Required permissions & scopes

Grant only the scopes below. Each one maps to a specific B6AI capability; requesting fewer reduces risk and speeds up any review your Gmail administrator performs. The table explains exactly what each scope allows and why it is needed.

Scope / permissionWhat it allowsWhy B6AI needs it
gmail.readonlyRead messages and metadataTriage and classify inbound email
gmail.sendSend email as the mailboxSend replies from a conversation
gmail.modifyModify message labels and stateApply labels and mark messages handled
gmail.labelsCreate and manage labelsSet up the routing labels your flows use
openid, emailIdentify the authorized accountConfirm which mailbox you connected

Finish configuration inside Gmail

Complete these steps in the Gmail console before connecting B6AI, so the credentials are fully active.

  1. If your consent screen is External, either Publish it or keep it in Testing with your mailbox added as a Test user.
  2. Confirm the exact B6AI redirect URL is listed under Authorized redirect URIs (a mismatch is the most common failure).
  3. Note: External apps using restricted Gmail scopes in production may require Google’s verification review.

Connect Gmail in B6AI

Now enter your credentials in B6AI. Signed in as an Enterprise Admin, open Settings → Integrations, find the Gmail card and click Connect, then complete the form. Every field is explained below.

  1. In B6AI, open Settings → Integrations → Gmail and click Connect.
  2. Paste the Client ID and Client secret.
  3. Click Connect and choose the Google mailbox in the consent popup, then grant the requested scopes.
  4. Optionally set the labels B6AI should apply to handled mail.
  5. Click Save: B6AI stores the refresh token.
json
{
  "provider": "gmail",
  "client_id": "…apps.googleusercontent.com",
  "client_secret": "GOCSPX-…",
  "scopes": ["gmail.readonly", "gmail.send", "gmail.modify"]
}
FieldWhat it isExample value
Client IDYour OAuth client identifier1234-abc.apps.googleusercontent.com
Client secretYour OAuth client secretGOCSPX-…
Authorized mailboxThe Gmail address you consented withsupport@yourco.com
Default labelLabel applied to handled messagesB6AI/Handled

Verify the connection

Confirm the integration is live before you rely on it in a bot.

  1. Confirm the Gmail card shows “Connected”.
  2. Run the Send test email action to an address you control.
  3. Confirm the email arrives and that any configured label was applied.
Connected
A green “Connected” status plus a successful test confirms Gmail is ready to use in your bots, action nodes and automations.

Troubleshooting

If the connection fails or an action does not work, match the symptom below to its cause and fix.

Symptom / errorLikely causeHow to fix it
redirect_uri_mismatchThe redirect URL isn’t registered exactlyAdd the exact B6AI redirect URL to the OAuth client’s Authorized redirect URIs
access_deniedConsent screen unpublished, or the account isn’t a test userPublish the consent screen, or add the mailbox under Test users
403 insufficientPermissionsA required scope is missingAdd the scope on the consent screen and reconnect
invalid_grantRefresh token expired or revokedReconnect to issue a fresh refresh token

Limitations & rate limits

Keep these constraints in mind so your bots behave predictably at scale.

  1. Gmail API usage is subject to per-user rate limits and daily quotas on your Google Cloud project.
  2. External apps using restricted scopes may require Google verification before broad use.
  3. Sending volume must stay within Gmail/Workspace sending policy.
Rate limits
Gmail enforces per-user and per-project quotas; sustained high volume may require a quota increase in Google Cloud.

Security best practices

  1. Grant only the scopes and permissions listed above, never request more “just in case”.
  2. Rotate your Google OAuth 2.0 credentials (Client ID & Secret) on a regular schedule, and immediately if you suspect exposure.
  3. Restrict the Enterprise Admin role (which manages integrations) to a small, trusted group.
  4. Prefer a dedicated service account or bot user over a personal login, so access survives staff changes.
  5. Review the integration’s activity in the B6AI Activity Logs periodically for unexpected calls.
  6. Disconnect the integration the moment a credential leaks; then rotate it in Gmail before reconnecting.

Recommendations

  1. Test against a sandbox or non-production Gmail account before connecting live data.
  2. Document which bots and flows depend on this integration so changes are predictable.
  3. Set a recurring reminder to review scopes and rotate credentials.
  4. Enable only the capabilities you actually use today; you can widen scopes later.
Was this page helpful?