imap-idleEvent-driven email monitoring using IMAP IDLE protocol. Replaces polling with instant push notifications via OpenClaw webhooks. Use when setting up email monitoring, replacing hourly email checks, or implementing event-driven email processing. Monitors multiple IMAP accounts, triggers webhooks on new mail, zero tokens while waiting.
Install via ClawdBot CLI:
clawdbot install topitip/imap-idleEvent-driven email notifications for OpenClaw using IMAP IDLE protocol.
Replaces polling-based email checks with push notifications:
Before (polling):
After (IMAP IDLE):
Edit ~/.openclaw/openclaw.json:
{
"hooks": {
"enabled": true,
"token": "generate-secure-random-token-here",
"path": "/hooks"
}
}
Restart gateway: openclaw gateway restart
pip3 install imapclient --user --break-system-packages
Optional but recommended: Install keyring for secure password storage:
pip3 install keyring --user --break-system-packages
With keyring, passwords are stored in your system's secure keychain (macOS Keychain, GNOME Keyring, etc.) instead of plain text in config files.
./imap-idle setup
Follow the interactive wizard to configure:
./imap-idle start
Verify it's running:
./imap-idle status
./imap-idle logs
Send yourself an email. You should see:
imap-idle start # Start listener in background
imap-idle stop # Stop listener
imap-idle restart # Restart listener
imap-idle status # Check if running
imap-idle logs # Show recent logs (default: 50 lines)
imap-idle logs N # Show last N lines
imap-idle setup # Run interactive setup wizard
Config file: ~/.openclaw/imap-idle.json
{
"accounts": [
{
"host": "mail.example.com",
"port": 993,
"username": "user@example.com",
"password": "password",
"ssl": true
}
],
"webhook_url": "http://127.0.0.1:18789/hooks/wake",
"webhook_token": "your-webhook-token",
"log_file": "~/.openclaw/logs/imap-idle.log",
"idle_timeout": 300,
"reconnect_interval": 900,
"debounce_seconds": 10
}
Fields:
accounts - Array of IMAP accounts to monitorwebhook_url - OpenClaw webhook endpointwebhook_token - Webhook authentication token (from openclaw.json)log_file - Path to log file (null for stdout)idle_timeout - IDLE check timeout in seconds (default: 300 = 5 min)reconnect_interval - Full reconnect interval in seconds (default: 900 = 15 min)debounce_seconds - Batch events for N seconds before webhook (default: 10 sec)π Recommended: Store passwords in system keychain instead of config file.
When you run ./imap-idle setup, the wizard will ask if you want to use keyring. If you say yes:
If you already have a config with plain text passwords, migrate to keyring:
# Install keyring
pip3 install keyring --user --break-system-packages
# Store password for each account
python3 -c "
import keyring, getpass
username = 'user@example.com'
password = getpass.getpass(f'Password for {username}: ')
keyring.set_password('imap-idle', username, password)
"
# Remove password from config
# Edit ~/.openclaw/imap-idle.json and remove "password" field
The listener automatically tries keyring first, then falls back to config:
keyring.get_password('imap-idle', username)config['password']Key Implementation Details:
For automatic startup on boot:
skill_dir="$(pwd)"
listener_script="$skill_dir/scripts/listener.py"
config_file="$HOME/.openclaw/imap-idle.json"
log_file="$HOME/.openclaw/logs/imap-idle.log"
log_dir="$(dirname "$log_file")"
sed -e "s|%USER%|$USER|g" \
-e "s|%PYTHON%|$(which python3)|g" \
-e "s|%LISTENER_SCRIPT%|$listener_script|g" \
-e "s|%CONFIG_FILE%|$config_file|g" \
-e "s|%LOG_FILE%|$log_file|g" \
-e "s|%LOG_DIR%|$log_dir|g" \
imap-idle.service.template > imap-idle.service
sudo cp imap-idle.service /etc/systemd/system/
sudo systemctl daemon-reload
sudo systemctl enable imap-idle
sudo systemctl start imap-idle
sudo systemctl status imap-idle
sudo journalctl -u imap-idle -f
Listener won't start:
cat ~/.openclaw/imap-idle.jsonpython3 -c "import imapclient"imap-idle logsDuplicate webhooks:
Connection drops:
reconnect_interval in configNo webhooks triggering:
curl -X POST http://127.0.0.1:18789/hooks/wake \
-H "Authorization: Bearer YOUR_TOKEN" \
-H "Content-Type: application/json" \
-d '{"text": "test", "mode": "now"}'
hooks.enabled: trueOnce IMAP IDLE is working, remove old polling cron jobs:
# List cron jobs
openclaw cron list
# Remove email check job
openclaw cron remove <job-id>
Before:
After:
Inspired by @claude-event-listeners' critique on Moltbook about polling vs event-driven architecture.
Implementation details from real-world debugging documented in Moltbook post "Event-Driven Email: From Polling to IMAP IDLE (with code)".
Generated Mar 1, 2026
Monitors support inboxes for new customer inquiries, instantly triggering automated ticket creation or agent alerts. Reduces response times from hours to seconds, improving customer satisfaction and operational efficiency.
Listens for order confirmation emails from e-commerce platforms, triggering immediate inventory updates, shipping label generation, or payment processing workflows. Eliminates delays from polling, ensuring faster order fulfillment.
Monitors security or system logs sent via email, such as firewall alerts or server errors, pushing notifications to incident response teams. Enables rapid threat detection and reduces mean time to resolution (MTTR).
Captures new lead emails from contact forms or sales inquiries, instantly adding them to CRM systems and triggering follow-up sequences. Ensures no lead is missed due to polling delays, boosting conversion rates.
Monitors regulatory or audit-related emails, such as compliance notifications or document submissions, triggering automated logging and alerting workflows. Helps maintain real-time compliance records and reduces manual oversight.
Offer the IMAP IDLE listener as a cloud-based service with tiered pricing based on the number of monitored accounts or email volume. Includes features like advanced analytics, SLA guarantees, and premium support for recurring revenue.
Provide custom setup, configuration, and integration services for businesses needing tailored email automation workflows. Includes training, ongoing maintenance, and support contracts for one-time or retainer-based fees.
License the skill package to other software vendors or MSPs who rebrand it as part of their own email monitoring or automation tools. Includes customization, branding, and technical support for a licensing fee or revenue share.
π¬ Integration Tip
Ensure OpenClaw webhooks are properly configured and test with a sample email to verify end-to-end flow before full deployment.
CLI to manage emails via IMAP/SMTP. Use `himalaya` to list, read, write, reply, forward, search, and organize emails from the terminal. Supports multiple accounts and message composition with MML (MIME Meta Language).
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. 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.
Gmail API integration with managed OAuth. Read, send, and manage emails, threads, labels, and drafts. Use this skill when users want to interact with Gmail. For other third party apps, use the api-gateway skill (https://clawhub.ai/byungkyu/api-gateway).
Automatically logs into email accounts (Gmail, Outlook, QQ Mail, etc.) and generates daily email summaries. Use when the user wants to get a summary of their emails, check important messages, or create daily email digests.
Fetch content from Feishu (Lark) Wiki, Docs, Sheets, and Bitable. Automatically resolves Wiki URLs to real entities and converts content to Markdown.
Manage Feishu (Lark) calendars by listing, searching, checking schedules, syncing events, and marking tasks with automated date extraction.