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.
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 can do with Gmail
Once connected, your bots and agents can use Gmail inside conversations and automations. Typical uses include:
- Read new inbound emails and classify them (for example by intent or priority).
- Send replies on behalf of the connected mailbox.
- Apply or remove labels to route messages or mark them handled.
- Create drafts for an agent to review before sending.
- 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.
- A Gmail or Google Workspace account with the mailbox you want to connect.
- Access to Google Cloud Console to create a project and an OAuth client.
- Permission to configure the OAuth consent screen for that project.
- 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.
- Go to console.cloud.google.com and create a new project (or pick an existing one).
- 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.
| Method | When to use it | Notes |
|---|---|---|
| Standard OAuth (recommended) | Connecting a single shared mailbox | Authorize the mailbox once via the consent popup; B6AI stores the refresh token. |
| Workspace domain-wide delegation | Accessing many mailboxes across a Google Workspace | A 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.
- 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.
- Open APIs & Services → Credentials → Create credentials → OAuth client ID → Application type: Web application.
- Under Authorized redirect URIs, add the B6AI redirect URL shown below.
- Click Create and copy the Client ID and Client secret.
https://app.b6ai.ai/integrations/gmail/callbackThe 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.
https://app.b6ai.ai/integrations/gmail/callbackRequired 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 / permission | What it allows | Why B6AI needs it |
|---|---|---|
| gmail.readonly | Read messages and metadata | Triage and classify inbound email |
| gmail.send | Send email as the mailbox | Send replies from a conversation |
| gmail.modify | Modify message labels and state | Apply labels and mark messages handled |
| gmail.labels | Create and manage labels | Set up the routing labels your flows use |
| openid, email | Identify the authorized account | Confirm which mailbox you connected |
Finish configuration inside Gmail
Complete these steps in the Gmail console before connecting B6AI, so the credentials are fully active.
- If your consent screen is External, either Publish it or keep it in Testing with your mailbox added as a Test user.
- Confirm the exact B6AI redirect URL is listed under Authorized redirect URIs (a mismatch is the most common failure).
- 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.
- In B6AI, open Settings → Integrations → Gmail and click Connect.
- Paste the Client ID and Client secret.
- Click Connect and choose the Google mailbox in the consent popup, then grant the requested scopes.
- Optionally set the labels B6AI should apply to handled mail.
- Click Save: B6AI stores the refresh token.
{
"provider": "gmail",
"client_id": "…apps.googleusercontent.com",
"client_secret": "GOCSPX-…",
"scopes": ["gmail.readonly", "gmail.send", "gmail.modify"]
}| Field | What it is | Example value |
|---|---|---|
| Client ID | Your OAuth client identifier | 1234-abc.apps.googleusercontent.com |
| Client secret | Your OAuth client secret | GOCSPX-… |
| Authorized mailbox | The Gmail address you consented with | support@yourco.com |
| Default label | Label applied to handled messages | B6AI/Handled |
Verify the connection
Confirm the integration is live before you rely on it in a bot.
- Confirm the Gmail card shows “Connected”.
- Run the Send test email action to an address you control.
- Confirm the email arrives and that any configured label was applied.
Troubleshooting
If the connection fails or an action does not work, match the symptom below to its cause and fix.
| Symptom / error | Likely cause | How to fix it |
|---|---|---|
| redirect_uri_mismatch | The redirect URL isn’t registered exactly | Add the exact B6AI redirect URL to the OAuth client’s Authorized redirect URIs |
| access_denied | Consent screen unpublished, or the account isn’t a test user | Publish the consent screen, or add the mailbox under Test users |
| 403 insufficientPermissions | A required scope is missing | Add the scope on the consent screen and reconnect |
| invalid_grant | Refresh token expired or revoked | Reconnect to issue a fresh refresh token |
Limitations & rate limits
Keep these constraints in mind so your bots behave predictably at scale.
- Gmail API usage is subject to per-user rate limits and daily quotas on your Google Cloud project.
- External apps using restricted scopes may require Google verification before broad use.
- Sending volume must stay within Gmail/Workspace sending policy.
Security best practices
- Grant only the scopes and permissions listed above, never request more “just in case”.
- Rotate your Google OAuth 2.0 credentials (Client ID & Secret) on a regular schedule, and immediately if you suspect exposure.
- Restrict the Enterprise Admin role (which manages integrations) to a small, trusted group.
- Prefer a dedicated service account or bot user over a personal login, so access survives staff changes.
- Review the integration’s activity in the B6AI Activity Logs periodically for unexpected calls.
- Disconnect the integration the moment a credential leaks; then rotate it in Gmail before reconnecting.
Recommendations
- Test against a sandbox or non-production Gmail account before connecting live data.
- Document which bots and flows depend on this integration so changes are predictable.
- Set a recurring reminder to review scopes and rotate credentials.
- Enable only the capabilities you actually use today; you can widen scopes later.