Email & Gmail Integration — Setup Guide
How to integrate Gmail and email with OpenClaw using the Gmail Pub/Sub system, gogcli tool, and custom skills. Includes troubleshooting for drafts not appearing and script execution issues.
⚠️ The Problem
🔍 Why This Happens
gogcli tool installed and authorized, (4) A public endpoint (via Tailscale or similar) for webhooks, and (5) Manual CLI setup.
Drafts Not Appearing: Common causes include: incorrect Gmail API scopes during authorization, rate limiting, or the draft being created in a different account than expected. The gogcli tool may also have stale OAuth tokens.
Scripts Stopped Working: When OpenClaw's sandbox mode is enabled (Docker-based or security policy), it blocks system.run commands by default. Scripts that worked before sandboxing was enabled will fail with permission errors. This is a security feature, not a bug.✅ The Fix
## Understanding Gmail Integration Options
There's no simple 'Connect Google Account' button in OpenClaw. Users who claim to have Google integration are using one of these approaches:
1. Gmail Pub/Sub Setup — Complex but official, requires Google Cloud 2. Custom Skills with gogcli — Scripts that call Google APIs via CLI 3. Browser Automation — Using unbrowse to control Gmail in a browser 4. IMAP/SMTP — Traditional email protocols (simpler but less features)
---
## Option 1: Gmail Pub/Sub Integration (Advanced)
This is the 'official' way documented in docs/automation/gmail-pubsub.md.
### Prerequisites
- Google Cloud project with billing enabled
- Pub/Sub API enabled in your project
- gogcli tool installed
- Tailscale (or other method) for public webhook endpoint
### Step 1: Install gogcli
# Install the Google CLI toolnpm install -g gogcli# orbrew install gogcli### Step 2: Authorize with Gmail
# This opens a browser for OAuth consentgogcli auth login --scopes gmail.readonly,gmail.send,gmail.composeImportant: Make sure you authorize with the correct scopes. Missing scopes = missing functionality.
### Step 3: Set up the webhook endpoint
# If using Tailscale Funnel for public endpointtailscale funnel 8080# Configure OpenClaw to receive Gmail webhooksopenclaw hooks gmail setup### Step 4: Test the integration
# Verify gogcli can access Gmailgogcli gmail list --limit 5# Check webhook statusopenclaw hooks gmail status---
## Option 2: Custom Skills for Google Calendar
Users have created skills that generate scripts for Google Calendar events.
### If Your Script Stopped Working
Error: "doesn't have the capability to run local scripts"
Cause: Sandbox mode is blocking system.run
### Fix 1: Check Sandbox Status
# Check if sandbox is enabledopenclaw config get sandbox.enabled# View sandbox settingsopenclaw config list | grep sandbox### Fix 2: Allowlist Your Script
If you trust the script, add it to the sandbox allowlist:
# Add script to allowed executablesopenclaw config set sandbox.allowlist.scripts "/path/to/your/calendar-script.sh"### Fix 3: Run Script Manually First
# Make script executablechmod +x ~/clawd/skills/google-calendar/create-event.sh# Test it directly~/clawd/skills/google-calendar/create-event.sh "Meeting" "2024-01-15 10:00" "2024-01-15 11:00"---
## Troubleshooting: Drafts Not Appearing in Gmail
### Step 1: Verify gogcli authorization
# Check current auth statusgogcli auth status# If expired, re-authorize with correct scopesgogcli auth login --scopes gmail.readonly,gmail.send,gmail.compose,gmail.modify### Step 2: Check the correct account
# See which account gogcli is usinggogcli auth whoami# If wrong account, logout and re-authgogcli auth logoutgogcli auth login### Step 3: Test draft creation directly
# Try creating a draft via CLIgogcli gmail draft create --to "test@example.com" --subject "Test" --body "Testing draft creation"# List recent draftsgogcli gmail drafts list --limit 5### Step 4: Check logs for errors
# View OpenClaw logs for Gmail-related errorsopenclaw logs --tail 100 | grep -i "gmail\|draft\|gog"---
## Option 3: Browser Automation for Gmail
If the API setup is too complex, use browser automation:
# Capture Gmail's internal APIopenclaw unbrowse capture --url "https://mail.google.com"# Or use the browser agentopenclaw unbrowse browse --url "https://mail.google.com" --task "compose email to test@example.com"---
## Sending Custom Data to OpenClaw Programmatically
To send messages, emails, or custom data streams to OpenClaw:
### Method 1: Webhooks
# Send data via webhookcurl -X POST http://localhost:8080/webhook/custom \ -H "Content-Type: application/json" \ -d '{"type": "email", "from": "user@example.com", "body": "Hello"}'### Method 2: Custom Channel Plugin
Create a custom channel in ~/.openclaw/channels/ that receives your data stream.
### Method 3: File-Based Ingestion
Write data to a watched directory that OpenClaw monitors:
``bash
echo '{"message": "Process this"}' > ~/.openclaw/inbox/email-001.json
🔥 Your AI should run your business, not just answer questions.
We'll show you how.$97/mo (going to $197 soon)
📋 Quick Commands
| Command | Description |
|---|---|
| gogcli auth login --scopes gmail.readonly,gmail.send,gmail.compose | Authorize gogcli with Gmail API scopes |
| gogcli auth status | Check current gogcli authorization status |
| gogcli auth whoami | See which Google account gogcli is using |
| gogcli gmail list --limit 5 | Test Gmail access by listing recent emails |
| gogcli gmail drafts list --limit 5 | List recent Gmail drafts to verify they're being created |
| openclaw hooks gmail setup | Set up Gmail Pub/Sub webhook integration |
| openclaw hooks gmail status | Check Gmail webhook integration status |
| openclaw config get sandbox.enabled | Check if sandbox mode is blocking script execution |
| tailscale funnel 8080 | Expose local port for Gmail webhook (requires Tailscale) |
| openclaw logs --tail 100 | grep -i gmail | View Gmail-related logs for troubleshooting |
Related Issues
📚 You Might Also Like
Set Up AI Email Assistant
Gmail Integration
Microsoft Outlook
Enterprise-grade integration with Microsoft 365 and Exchange Online. Manage email, calendar, and meetings with full Azure AD authentication and compliance support.
AI Assistant for Productivity: GTD, Email, and Workflow Optimization
AI assistants aren't just for questions — they're productivity multipliers. From GTD workflows to inbox zero, here's how to reclaim hours every week with AI.
🐙 Your AI should run your business.
Weekly live builds + template vault. We'll show you how to make AI actually work.$97/mo (going to $197 soon)
Join Vibe Combinator →