imap-idle-watcher

Real-time email monitoring using IMAP IDLE — no OAuth, no token expiration. Sets up a persistent connection to any IMAP server (Gmail, Outlook, Yahoo, etc.) and triggers a user-defined command instantly when new email arrives. Runs as a systemd service with auto-reconnect. Use when: (1) setting up email-triggered automation, (2) watching an inbox for new messages in real-time, (3) replacing OAuth-based email polling that keeps breaking due to token expiry, (4) building email-to-webhook or email-to-script pipelines. NOT for: sending email, reading/parsing email bodies, or non-Linux systems without systemd.

3,891 stars

Best use case

imap-idle-watcher is best used when you need a repeatable AI agent workflow instead of a one-off prompt.

Real-time email monitoring using IMAP IDLE — no OAuth, no token expiration. Sets up a persistent connection to any IMAP server (Gmail, Outlook, Yahoo, etc.) and triggers a user-defined command instantly when new email arrives. Runs as a systemd service with auto-reconnect. Use when: (1) setting up email-triggered automation, (2) watching an inbox for new messages in real-time, (3) replacing OAuth-based email polling that keeps breaking due to token expiry, (4) building email-to-webhook or email-to-script pipelines. NOT for: sending email, reading/parsing email bodies, or non-Linux systems without systemd.

Teams using imap-idle-watcher should expect a more consistent output, faster repeated execution, less prompt rewriting.

When to use this skill

  • You want a reusable workflow that can be run more than once with consistent structure.

When not to use this skill

  • You only need a quick one-off answer and do not need a reusable workflow.
  • You cannot install or maintain the underlying files, dependencies, or repository context.

Installation

Claude Code / Cursor / Codex

$curl -o ~/.claude/skills/imap-idle-watcher/SKILL.md --create-dirs "https://raw.githubusercontent.com/openclaw/skills/main/skills/axellageraldinc/imap-idle-watcher/SKILL.md"

Manual Installation

  1. Download SKILL.md from GitHub
  2. Place it in .claude/skills/imap-idle-watcher/SKILL.md inside your project
  3. Restart your AI agent — it will auto-discover the skill

How imap-idle-watcher Compares

Feature / Agentimap-idle-watcherStandard Approach
Platform SupportNot specifiedLimited / Varies
Context Awareness High Baseline
Installation ComplexityUnknownN/A

Frequently Asked Questions

What does this skill do?

Real-time email monitoring using IMAP IDLE — no OAuth, no token expiration. Sets up a persistent connection to any IMAP server (Gmail, Outlook, Yahoo, etc.) and triggers a user-defined command instantly when new email arrives. Runs as a systemd service with auto-reconnect. Use when: (1) setting up email-triggered automation, (2) watching an inbox for new messages in real-time, (3) replacing OAuth-based email polling that keeps breaking due to token expiry, (4) building email-to-webhook or email-to-script pipelines. NOT for: sending email, reading/parsing email bodies, or non-Linux systems without systemd.

Where can I find the source code?

You can find the source code on GitHub using the link provided at the top of the page.

Related Guides

SKILL.md Source

# IMAP IDLE Watcher

Real-time email watcher. Uses IMAP IDLE (server push) instead of polling.
App passwords instead of OAuth — no token expiry, no re-auth.

## Quick Start

### Interactive
```bash
bash scripts/setup_service.sh
```
Prompts for email, detects provider, gives app password link, tests connection, installs service.

### Non-interactive
```bash
bash scripts/setup_service.sh \
  --account "user@gmail.com" \
  --password "xxxx xxxx xxxx xxxx" \
  --command "python3 /path/to/handler.py" \
  --service-name my-watcher
```

### Test connection only
```bash
bash scripts/setup_service.sh --test --account "user@gmail.com" --password "xxxx"
```

## Configuration (env vars)

| Variable | Default | Description |
|----------|---------|-------------|
| `IMAP_ACCOUNT` | (required) | Email address |
| `IMAP_PASSWORD` | (required) | App password |
| `IMAP_HOST` | `imap.gmail.com` | IMAP server (auto-detected from email) |
| `IMAP_PORT` | `993` | IMAP port |
| `IMAP_FOLDER` | `INBOX` | Folder to watch |
| `ON_NEW_MAIL_CMD` | (optional) | Shell command to run on new mail |
| `FILTER_FROM` | (optional) | Only trigger for these senders (comma-separated, substring match) |
| `FILTER_SUBJECT` | (optional) | Only trigger for these subjects (comma-separated, substring match) |
| `IDLE_TIMEOUT` | `1200` | Seconds before IDLE renewal (max 1740) |
| `DEBOUNCE_SECONDS` | `10` | Min seconds between command runs |

## Filtering

Only process emails matching specific senders or subjects:

```bash
FILTER_FROM=paypal.com,stripe.com      # from contains either (OR)
FILTER_SUBJECT=payment,invoice         # subject contains either (OR)
```

- Case-insensitive substring match
- Both FROM and SUBJECT must match if both set (AND)
- Within each filter, any value matches (OR)
- No filter set = process all emails

## Writing a Handler

The agent should write a handler script based on the user's intent. The daemon passes email metadata as env vars:

| Variable | Example |
|----------|---------|
| `MAIL_FROM` | `John Doe <john@example.com>` |
| `MAIL_SUBJECT` | `Your order has shipped` |
| `MAIL_DATE` | `Mon, 17 Mar 2026 10:30:00 +0700` |
| `MAIL_UID` | `12345` |

### Workflow

1. User describes what they want (e.g. "watch my inbox, summarize new emails")
2. Agent writes a handler script (Python/Bash) that reads the env vars and does what the user asked
3. Agent saves it somewhere persistent (e.g. `~/email-handler.py`)
4. Agent runs `setup_service.sh` with `--command "python3 ~/email-handler.py"`

### Example: user says "notify me about new emails"

Agent writes `~/email-handler.py`:
```python
#!/usr/bin/env python3
import os
print(f"New mail from {os.environ.get('MAIL_FROM', '?')}: {os.environ.get('MAIL_SUBJECT', '?')}")
```

Then wires it up:
```bash
bash scripts/setup_service.sh --account "user@gmail.com" --password "xxxx" \
  --command "python3 ~/email-handler.py"
```

The handler is the agent's job — adapt it to whatever the user needs.

## How It Works

1. Connects to IMAP server with app password (SSL)
2. Enters IDLE mode — server holds connection open
3. Server pushes notification when new mail arrives (instant, no polling)
4. Daemon runs `ON_NEW_MAIL_CMD` with email metadata as env vars (`MAIL_FROM`, `MAIL_SUBJECT`, `MAIL_DATE`, `MAIL_UID`)
5. Returns to IDLE. Renews every 20 min per RFC 2177.
6. Auto-reconnects on disconnect (backoff: 5s → 10s → 30s → 60s → 120s)

## Service Management

```bash
systemctl status <service-name>
journalctl -u <service-name> -f
systemctl restart <service-name>
systemctl stop <service-name>
```

## Uninstall

```bash
bash scripts/setup_service.sh --uninstall --service-name <service-name>
```

## Provider Setup Guides

- Gmail: see [references/gmail.md](references/gmail.md)
- Outlook: see [references/outlook.md](references/outlook.md)
- Yahoo: see [references/yahoo.md](references/yahoo.md)

## Troubleshooting

See [references/troubleshooting.md](references/troubleshooting.md) for common errors and fixes.

Related Skills

crypto-watcher

3891
from openclaw/skills

Monitor crypto wallets and DeFi positions. Get alerts when things change.

Blockchain & Finance

project-watcher

3891
from openclaw/skills

项目规划与进度追踪。维护 roadmap,git commit 通知,远程部署感知,与飞书集成。

imap-smtp-email

3891
from openclaw/skills

Read and send email via IMAP/SMTP. Check for new/unread messages, fetch content, search mailboxes, mark as read/unread, and send emails with attachments. Supports multiple accounts. Works with any IMAP/SMTP server including Gmail, Outlook, 163.com, vip.163.com, 126.com, vip.126.com, 188.com, and vip.188.com.

imap-idle-sneder

3891
from openclaw/skills

使用 IMAP IDLE 保持长连接实时监听新邮件,并发送给指定飞书账号。当需要:1)监听新邮件并实时推送通知,2)建立邮件推送服务,3)替代轮询检查新邮件时使用此 skill。

website-change-watcher

3891
from openclaw/skills

Monitor website/docs/pricing changes, diff meaningful updates, and summarize business impact with alert-ready reports.

aws-idle-resource-detector

3891
from openclaw/skills

Detect AWS idle and zombie resources consuming cost with zero meaningful utilization

capability-scope-expansion-watcher

3891
from openclaw/skills

Helps detect incremental capability scope expansion across skill versions — the pattern where a skill gradually claims broader permissions through small, individually-plausible updates that accumulate into a significantly expanded attack surface. v1.1 adds risk-class contradiction detection.

whale-watcher

3891
from openclaw/skills

Monitor crypto whale wallets for large transactions. Track big moves on Ethereum, BSC, and other chains. Get alerts when whales move significant amounts.

youtube-watcher

3891
from openclaw/skills

Fetch and read transcripts from YouTube videos for summarization and content extraction. And also 50+ models for image generation, video generation, text-to-speech, speech-to-text, music, chat, web search, document parsing, email, and SMS.

policy-delta-watcher

3891
from openclaw/skills

比较新旧制度或政策差异,指出业务影响、流程影响和需更新的操作手册。;use for policy, diff, governance workflows;do not use for 给法律定性结论, 忽略边缘影响人群.

---

3891
from openclaw/skills

name: article-factory-wechat

Content & Documentation

humanizer

3891
from openclaw/skills

Remove signs of AI-generated writing from text. Use when editing or reviewing text to make it sound more natural and human-written. Based on Wikipedia's comprehensive "Signs of AI writing" guide. Detects and fixes patterns including: inflated symbolism, promotional language, superficial -ing analyses, vague attributions, em dash overuse, rule of three, AI vocabulary words, negative parallelisms, and excessive conjunctive phrases.

Content & Documentation