Sets up mail-agent — an AI Gmail monitor that runs inside OpenClaw and delivers important emails to your Telegram.
When invoked, walk the user through every step below in order. Check each prerequisite before proceeding. Do not skip steps.
bash
gog auth list
If no accounts are listed, stop and tell the user to set up gog first:
bash
gog auth credentials /path/to/client_secret.json
gog auth add you@gmail.com --services gmail
Note which Gmail account is being watched ( GOG_ACCOUNT or the default).
bash
gcloud auth application-default print-access-token 2>&1 | head -1
If this fails (not logged in):
bash
gcloud auth application-default login
Check if a suitable GCP project exists:
bash
gcloud projects list
If no project exists, create one:
bash
gcloud projects create mail-agent-YOUR_NAME --name "Mail Agent"
gcloud config set project mail-agent-YOUR_NAME
If a project exists, set it:
bash
gcloud config set project YOUR_PROJECT_ID
Note the project ID — needed for plugin config.
bash
gcloud services enable gmail.googleapis.com pubsub.googleapis.com
bash
gcloud pubsub topics create mail-agent-inbox
gcloud pubsub subscriptions create mail-agent-inbox-sub --topic=mail-agent-inbox
Grant Gmail permission to publish to the topic:
bash
gcloud pubsub topics add-iam-policy-binding mail-agent-inbox \
--member="serviceAccount:gmail-api-push@system.gserviceaccount.com" \
--role="roles/pubsub.publisher"
bash
openclaw plugins install https://github.com/nanaco666/openclaw-mail-agent/archive/refs/tags/v0.2.1.tar.gz
Set required values (replace placeholders):
bash
openclaw plugins config mail-agent --set chatId=YOUR_TELEGRAM_CHAT_ID
openclaw plugins config mail-agent --set gcpProject=YOUR_GCP_PROJECT_ID
openclaw plugins config mail-agent --set pubsubSubscription=mail-agent-inbox-sub
Set LLM for email classification (recommended — skip to use pass-through):
bash
openclaw plugins config mail-agent --set llmApiKey=sk-...
openclaw plugins config mail-agent --set llmModel=gpt-4o-mini
To find your Telegram chat ID: message @userinfobot on Telegram.
bash
openclaw gateway restart
Wait a few seconds, then check logs:
bash
openclaw gateway logs | grep mail-agent
Expected output:
text
mail-agent: watch registered, historyId=...
mail-agent: watching inbox
If you see watch registration failed, re-check Step 3 and Step 4.
Send a test email to the watched Gmail account with urgent content, e.g.:
Subject: Urgent: server is down Body: Production database crashed, users can't log in.
Wait up to 60 seconds. A notification should arrive in Telegram.
If nothing arrives after 2 minutes:
bash
openclaw gateway logs | grep mail-agent
Common issues:
telegram runtime not available → restart OpenClaw gatewaywatch registration failed → APIs not enabled or wrong projectsubscription error → subscription name mismatch, check Step 4openclaw plugins listbash
openclaw plugins config mail-agent --set KEY=VALUE
openclaw gateway restart
bash
openclaw plugins uninstall mail-agent
openclaw gateway restart