Real-time email watcher. Uses IMAP IDLE (server push) instead of polling. App passwords instead of OAuth — no token expiry, no re-auth.
bash
bash scripts/setup_service.sh
Prompts for email, detects provider, gives app password link, tests connection, installs service.
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
bash
bash scripts/setup_service.sh --test --account "user@gmail.com" --password "xxxx"
VariableDefaultDescriptionIMAP_ACCOUNT(required)Email addressIMAP_PASSWORD(required)App passwordIMAP_HOST``imap.gmail.comIMAP server (auto-detected from email)IMAP_PORT``993IMAP portIMAP_FOLDER``INBOXFolder to watchON_NEW_MAIL_CMD(optional)Shell command to run on new mailFILTER_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``1200Seconds before IDLE renewal (max 1740)DEBOUNCE_SECONDS``10Min seconds between command runs
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)
The agent should write a handler script based on the user's intent. The daemon passes email metadata as env vars:
VariableExampleMAIL_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
~/email-handler.py)setup_service.sh with --command "python3 ~/email-handler.py"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.
ON_NEW_MAIL_CMD with email metadata as env vars ( MAIL_FROM, MAIL_SUBJECT, MAIL_DATE, MAIL_UID)bash
systemctl status <service-name>
journalctl -u <service-name> -f
systemctl restart <service-name>
systemctl stop <service-name>
bash
bash scripts/setup_service.sh --uninstall --service-name <service-name>
See references/troubleshooting.md for common errors and fixes.