email-imap-fetch
Original:🇺🇸 English
Translated
1 scripts
Listen for one or more IMAP inboxes with the IDLE command, fetch unread email metadata plus text previews, and forward each message to OpenClaw webhooks. Use when tasks need near-real-time mailbox monitoring, multi-account inbox ingestion via environment variables, and automatic trigger delivery into OpenClaw automation.
9installs
Sourcetiangong-ai/skills
Added on
NPX Install
npx skill4agent add tiangong-ai/skills email-imap-fetchTags
Translated version includes tags in frontmatterSKILL.md Content
View Translation Comparison →Email IMAP Fetch
Core Goal
- Wait for new mail with IMAP IDLE.
- Fetch unread messages after each wake-up.
- Support multiple mailbox accounts configured with env.
- Control IDLE support strictly with env mode (or
idle) without runtime probing.poll - Forward each fetched email to OpenClaw webhooks.
- Emit machine-readable JSON lines for downstream steps.
Workflow
- Configure account env variables and OpenClaw webhook env variables (see and
references/env.md).assets/config.example.env - Validate configuration:
bash
python3 scripts/imap_idle_fetch.py check-config- Run one IDLE cycle per account (smoke test):
bash
python3 scripts/imap_idle_fetch.py listen --cycles 1 --idle-seconds 120 --max-messages 10- Run continuously (default resident mode):
bash
python3 scripts/imap_idle_fetch.py listenRuntime Model
- Skill files are installed locally, but the listener is not auto-started.
- In mode, IMAP IDLE receives push events only while listener process and IMAP connection are alive.
idle - In mode, listener sleeps for poll interval and then fetches unread messages.
poll - If the process exits, push events are missed; next run can still fetch existing unread emails with .
UNSEEN - Default runtime is resident mode (by default).
IMAP_CYCLES=0 - Default IDLE mode is (safe for servers without IDLE support).
poll - For always-on behavior in production, manage the process with ,
systemd,launchd, or an equivalent daemon manager.supervisor
Output Contract
- Output format is JSONL (one JSON object per line).
- for lifecycle events.
type=status - for fetched emails with:
type=message- ,
account,mailbox,sequid - ,
subject,from,to,datemessage_id - (plain-text preview)
snippet
- is
wait_modeoridlein cycle status output.poll - records the active wait strategy details.
wait_events - status events when OpenClaw webhook POST succeeds.
event=webhook_delivered - for account-level failures.
type=error - error events when OpenClaw webhook POST fails.
event=webhook_failed
Parameters
- : IDLE cycles per account (
--cyclesmeans forever).0 - : max wait time for each IDLE call.
--idle-seconds - : interval used when polling mode is active.
--poll-seconds - :
--idle-modeoridle.poll - : max unread emails fetched each cycle.
--max-messages - /
--mark-seen: control unread state updates.--no-mark-seen - : preview length limit.
--snippet-chars - : connection timeout seconds.
--connect-timeout - : retry delay after failure.
--retry-seconds
Environment defaults:
IMAP_CYCLESIMAP_IDLE_MODEIMAP_IDLE_SECONDSIMAP_POLL_SECONDSIMAP_MAX_MESSAGESIMAP_MARK_SEENIMAP_SNIPPET_CHARSIMAP_CONNECT_TIMEOUTIMAP_RETRY_SECONDS
OpenClaw webhooks forwarding:
OPENCLAW_WEBHOOKS_ENABLEDOPENCLAW_WEBHOOKS_TOKENOPENCLAW_WEBHOOKS_BASE_URL- (
OPENCLAW_WEBHOOKS_MODEoragent)wake - (optional endpoint override)
OPENCLAW_WEBHOOKS_ENDPOINT OPENCLAW_WEBHOOKS_PATHOPENCLAW_WEBHOOKS_WAKE_MODEOPENCLAW_WEBHOOKS_DELIVEROPENCLAW_WEBHOOKS_TIMEOUTOPENCLAW_WEBHOOKS_NAMEOPENCLAW_WEBHOOKS_AGENT_IDOPENCLAW_WEBHOOKS_CHANNELOPENCLAW_WEBHOOKS_TOOPENCLAW_WEBHOOKS_MODELOPENCLAW_WEBHOOKS_THINKINGOPENCLAW_WEBHOOKS_AGENT_TIMEOUT_SECONDSOPENCLAW_WEBHOOKS_SESSION_KEY_PREFIX
Error Handling
- Invalid env configuration exits with code .
2 - In mode, unsupported IDLE returns explicit error and suggests
idle.IMAP_IDLE_MODE=poll - Runtime failures are emitted as .
type=error - Command exits non-zero when account processing errors occur.
References
references/env.md
Assets
assets/config.example.env
Scripts
scripts/imap_idle_fetch.py