Mail Auto Reply(多通道:Agent Mail + Gmail)
Overview
Drives a complete email auto-reply cycle across two channels:
- Agent Mail — via the
agent-mailconnector (MCP tools:ListMessages/SearchMessages/GetMessage/ReplyMessage/SendMessage). - Gmail — via the
gogCLI (Google Workspace CLI, binarygog).
For each selected channel it verifies login, reads new/unread mail, replies per a user-supplied persona + policy, and emits a 邮件往来简报.md briefing plus a chat summary. Persona/tone is NEVER hardcoded — collected at runtime so each user applies their own voice.
When To Use
- The user asks to "处理邮件 / 自动回复 / 回复新邮件 / 出邮件简报".
- The user opens the 邮件自动回复管家 expert and invokes this skill.
- The user wants a safe, auditable mailbox pass over Agent Mail and/or Gmail.
Prerequisites
Agent Mail
agent-mailconnector connected; user has logged into the mailbox athttps://agent.qq.com.- If
GetMereturnsnot_bound, guide the user to WorkBuddy 「更多 → 我的邮箱」to enable the mailbox first.
Gmail (requires the gog CLI)
gogbinary installed and on PATH. Install (pick one):- macOS / Linux:
brew install gogcli— orgo install github.com/openclaw/gogcli/cmd/gog@latest(needs Go). - Windows: download
gogcli_*_windows_amd64.zipfromhttps://github.com/openclaw/gogcli/releases, extractgog.exe, put it on PATH. - One-time OAuth (Google requires this; no way around it):
1. Google Cloud Console → create a "Desktop app" OAuth client → downloadclient_secret.json.
2.gog auth credentials ~/Downloads/client_secret.json
3.gog auth add you@gmail.com --services gmail(opens browser for consent).
4.export GOG_ACCOUNT=you@gmail.com(or pass--accounton every call). - Verify:
gog auth listandgog gmail search 'is:unread' --max 1 --json.
Workflow
0. Channel selection (new)
Ask which channel(s) to process if not already stated: Agent Mail / Gmail / Both. Apply the matching branch below for each selected channel.
1. Login pre-check (per channel, mandatory)
- Agent Mail: open
https://agent.qq.com, confirm the inbox is visible and logged in. If not, say "请用微信扫码重新登录 Agent Mail" and STOP until the user confirms. (You may also probe viaagent-mailGetMe; onnot_bound, guide "更多 → 我的邮箱" to enable.) - Gmail: run
gog auth list(orgog gmail search 'is:unread' --max 1 --json). If no authed account or an auth error appears, STOP and tell the user to rungog auth credentials+gog auth add(see Prerequisites). Never proceed without a working Gmail auth.
2. Collect runtime parameters (ask if missing)
Confirm in one go when not already provided:
- Persona/tone — e.g. "热情专业的拉新顾问", "简洁客服助手". (Never assume a fixed persona.)
- Reply policy — full auto-reply / FAQ-template only / draft-only.
- Whitelist — only reply to which senders / subjects (optional).
- Send mode — send directly / draft for review.
3. Read emails (per channel)
- Agent Mail: pull new/unread via
ListMessages/SearchMessages; useGetMessagefor full body. - Gmail:
gog gmail search 'is:unread newer_than:7d' --max 50 --json(parse threads/messages; prefer--json+--no-input). Read a thread body with the appropriate get/read subcommand — checkgog gmail --help(commonlygog gmail get <messageId> --json). - Filter out
no-reply, subscription pushes, and automated bounce/return receipts on both channels. - Maintain a "replied IDs" record in a local file, keyed by
channel:messageId, to prevent duplicate replies.
4. Reply handling (per channel)
- Agent Mail:
ReplyMessage/SendMessage. - Gmail:
- Check
gog gmail --helpfor areplysubcommand; if present, prefer it for correct threading. - Otherwise
gog gmail send --to <from> --subject "Re: <original subject>" --body "<reply>"(briefly quote the original). - Draft mode: create a draft via
gog gmail drafts create ...(or--draftif supported) and tell the user; do NOT send. - Direct send: execute the send.
- Draft for review: produce the draft and clearly tell the user; do NOT send.
- Sensitive / undecidable / VIP: escalate to human (draft + notify user).
5. Produce briefing
- Generate
邮件往来简报.mdinto the user's working directory. - Include: run time, per-channel mailbox address, received mails (sender / subject / summary / replied?), sent or drafted (recipient / subject / summary), unhandled items with reasons, and per-channel quota usage:
- Agent Mail: 50 sends/mailbox/day.
- Gmail: Google has no fixed daily cap but enforces rate limits — note any send errors.
- Give a 3–5 point chat summary (no long-form dump).
Guardrails (must enforce)
- Dedupe: track
channel:messageIdlocally; never reply twice. - Loop prevention: never auto-reply to automated systems; filter
no-reply/ subscription / bounce mail on both channels. - Quota: Agent Mail 50/day (warn + pause as the limit nears). Gmail: watch for rate-limit errors and back off.
- Escalate: sensitive / undecidable / VIP → draft + notify, never blind-send.
- Client must stay running: if later wired to a scheduled automation, the WorkBuddy client must remain open or it will not trigger.
- No hardcoded persona: every reply derives from the user-supplied tone for that run.
- Gmail auth safety: never attempt to send before
gog auth listshows a valid account.
Sharing With Colleagues
- Copy this skill directory into the colleague's
~/.workbuddy/skills/to install. - Each person must use their OWN Agent Mail mailbox (max 2 per WeChat account) and their OWN Gmail OAuth — Google does not permit shared mailbox auth. Do not share one mailbox/account (quota + identity collision).
- Optionally bundle inside an expert package's
skills/folder so the expert ships with it.