Gmail Configuration
Gmail Integration
Section titled “Gmail Integration”OpenClaw can integrate with Gmail to read emails, send replies, and manage your inbox. This integration uses Google Cloud Pub/Sub to push real-time notifications to your Gateway, ensuring your agent reacts immediately to new messages.
Prerequisites
Section titled “Prerequisites”- Google Cloud Account: You need to create a project in the Google Cloud Console.
gcloudCLI: Installed and logged in (Install Guide).gog(gogcli): Helper tool for Gmail OAuth and setup (gogcli.sh).- Tailscale (Recommended): Used to expose a secure public endpoint for Pub/Sub webhooks.
Setup Wizard (Recommended)
Section titled “Setup Wizard (Recommended)”The easiest way to set up Gmail is using the OpenClaw CLI wizard, which automates the OAuth and Pub/Sub wiring.
Run the Setup Command Use the
webhooks gmail setupcommand. Replaceyou@gmail.comwith your email address.Terminal window openclaw webhooks gmail setup --account you@gmail.comThis command will:
- Guide you through Google Cloud authentication.
- Create a Pub/Sub topic and subscription.
- Configure a
watchon your Gmail inbox. - Generate the necessary OpenClaw configuration.
Start the Watcher Once setup is complete, you can start the runtime watcher (or restart your Gateway).
Terminal window openclaw webhooks gmail runNote: The Gateway automatically starts this service if configured.
Manual Configuration
Section titled “Manual Configuration”If you prefer to configure it manually or need to customize the behavior, add the following to your ~/.openclaw/openclaw.json.
Basic Config
Section titled “Basic Config”{ hooks: { gmail: { account: "openclaw@gmail.com", // Pub/Sub details (generated by setup wizard) topic: "projects/my-project/topics/gmail-watch", subscription: "gmail-watch-sub", pushToken: "secret-token",
// Where Google pushes events (Tailscale Funnel URL) hookUrl: "https://my-tailnet.ts.net/hooks/gmail",
// Local server to receive the push serve: { bind: "127.0.0.1", port: 8788, path: "/" } } }}Routing & Agent Behavior
Section titled “Routing & Agent Behavior”To control how the agent processes emails, configure the hooks.mappings section.
{ hooks: { enabled: true, presets: ["gmail"], // Enable the default gmail handler mappings: [ { match: { path: "gmail" }, action: "agent", wakeMode: "now", // Wake up immediately name: "Gmail", // Unique session key prevents mixing emails with other chats sessionKey: "hook:gmail:{{messages[0].id}}",
// Context template for the model messageTemplate: "New email from {{messages[0].from}}\nSubject: {{messages[0].subject}}\n{{messages[0].snippet}}\n{{messages[0].body}}",
// Use a cheaper/faster model for email triage? model: "openai/gpt-4o-mini",
// Delivery: Send the agent's reply back to the user via WhatsApp/Telegram deliver: true, channel: "last" // Or specify specific channel like "telegram" } ] }}Advanced Options
Section titled “Advanced Options”You can enforce a specific model for Gmail tasks to save costs or improve speed.
{ hooks: { gmail: { // Global default for Gmail hooks model: "openrouter/meta-llama/llama-3.3-70b-instruct:free", thinking: "off" } }}By default, external content in emails is wrapped in safety boundaries.
Troubleshooting
Section titled “Troubleshooting”- Watch Expiration: Gmail watches expire after 7 days. OpenClaw automatically renews them if the Gateway is running.
- Tailscale Funnel: Ensure your Tailscale Funnel is active and publicly accessible if you rely on it for the webhook URL.
- Permissions: If you see 403 errors, check your Google Cloud IAM permissions for the Pub/Sub service account.