IMAP/SMTP Email: Universal Email Control for AI Agents
With over 17,000 downloads, imap-smtp-email is ClawHub's most widely used email integration. Unlike API-based email skills that require provider-specific credentials and support only select services, this skill uses the standard IMAP and SMTP protocols — which means it works with any email provider that exposes these interfaces: Gmail, Outlook, 163.com, 126.com, 188.com, vip.163.com, QQ Mail, yeah.net, and any custom mail server.
The Problem It Solves
Most email integrations for AI agents are either too narrow (Gmail only, via OAuth) or too abstract (API wrappers that hide protocol details). For teams managing email in enterprise environments, using Chinese email providers, or running self-hosted mail servers, these options don't work.
IMAP and SMTP are the lowest-common-denominator protocols that every email server supports. By building on them directly, imap-smtp-email covers the entire email ecosystem — read any inbox, send from any account, download any attachment — without provider lock-in.
Architecture
The skill is two Node.js CLI scripts:
imap.js— reads email via IMAP (check, fetch, search, download attachments, mark read/unread, list mailboxes)smtp.js— sends email via SMTP (plain text, HTML, attachments, CC, BCC)
Both use environment variables for credentials and output structured JSON, making them straightforward for Claude to parse and act on.
Setup
Provider Configuration
The skill includes a setup.sh wizard that interactively builds your .env file with pre-configured settings for 10 common providers. Or configure manually:
# IMAP (receiving)
IMAP_HOST=imap.gmail.com
IMAP_PORT=993
IMAP_USER=you@gmail.com
IMAP_PASS=your_app_password
IMAP_TLS=true
IMAP_MAILBOX=INBOX
# SMTP (sending)
SMTP_HOST=smtp.gmail.com
SMTP_PORT=587
SMTP_SECURE=false
SMTP_USER=you@gmail.com
SMTP_PASS=your_app_password
SMTP_FROM=you@gmail.comInstall dependencies:
npm installCommon Server Settings
| Provider | IMAP Host | IMAP Port | SMTP Host | SMTP Port |
|---|---|---|---|---|
| Gmail | imap.gmail.com | 993 | smtp.gmail.com | 587 |
| Outlook | outlook.office365.com | 993 | smtp.office365.com | 587 |
| QQ Mail | imap.qq.com | 993 | smtp.qq.com | 587 |
| 163.com | imap.163.com | 993 | smtp.163.com | 465 |
| vip.163.com | imap.vip.163.com | 993 | smtp.vip.163.com | 465 |
| 126.com | imap.126.com | 993 | smtp.126.com | 465 |
| yeah.net | imap.yeah.net | 993 | smtp.yeah.net | 465 |
163.com users: Use the authorization code (授权码), not your account password. Enable IMAP/SMTP in web settings first.
Gmail users: If 2FA is enabled, use an App Password — not your account password.
Reading Email (IMAP)
Check Recent Messages
# Last 10 emails in INBOX
node scripts/imap.js check --limit 10
# Emails from the last 2 hours
node scripts/imap.js check --recent 2h
# Only unread messages from last 30 minutes
node scripts/imap.js check --recent 30m --unseenTime format: 30m (minutes), 2h (hours), 7d (days).
Response is a JSON array of message objects including uid, from, to, subject, date, body text/html, and flags.
Fetch a Specific Email
# Get full content by UID
node scripts/imap.js fetch 12345Returns parsed email with headers, body (plain and HTML), and attachment metadata.
Search Emails
# All unread
node scripts/imap.js search --unseen
# From a specific sender
node scripts/imap.js search --from "boss@company.com"
# By subject
node scripts/imap.js search --subject "invoice"
# Date range
node scripts/imap.js search --since 2026-01-01 --before 2026-02-01
# Combined: unread invoices from last week
node scripts/imap.js search --unseen --subject "invoice" --recent 7d --limit 20Search criteria are combined (AND logic). Results sorted newest-first.
Download Attachments
# Download all attachments from email UID 12345
node scripts/imap.js download 12345 --dir ./downloads
# Download a specific file only
node scripts/imap.js download 12345 --file report.pdf --dir ./downloadsIf --file is specified and not found, the response lists available attachment filenames.
Manage Read Status
node scripts/imap.js mark-read 12345
node scripts/imap.js mark-unread 12345
# Multiple UIDs at once
node scripts/imap.js mark-read 12345 12346 12347List Mailboxes
node scripts/imap.js list-mailboxesReturns the full mailbox tree — useful for identifying folder names when searching outside INBOX (e.g., Sent, Spam, custom folders).
Sending Email (SMTP)
Simple Text Email
node scripts/smtp.js send \
--to recipient@example.com \
--subject "Hello" \
--body "World"HTML Email
node scripts/smtp.js send \
--to recipient@example.com \
--subject "Weekly Newsletter" \
--html \
--body "<h1>Updates</h1><p>Here's what happened this week...</p>"Or from an HTML file:
node scripts/smtp.js send \
--to recipient@example.com \
--subject "Report" \
--html-file report.htmlEmail with Attachment
node scripts/smtp.js send \
--to client@example.com \
--subject "Invoice #1234" \
--body "Please find the invoice attached." \
--attach invoice.pdfMultiple attachments (comma-separated):
--attach "report.pdf,data.xlsx,screenshot.png"Multiple Recipients with CC and BCC
node scripts/smtp.js send \
--to "alice@company.com,bob@company.com" \
--cc "manager@company.com" \
--bcc "audit@company.com" \
--subject "Quarterly Update" \
--body "Please review the attached materials." \
--attach q1-report.pdfTest SMTP Connection
node scripts/smtp.js testSends a test email to yourself to verify the SMTP configuration before relying on it in production.
Practical Workflows
Monitor a Specific Sender
"Check if I have any unread emails from vendor@supplier.com in the last 24 hours"
Claude runs:
node scripts/imap.js search --from "vendor@supplier.com" --recent 24h --unseenProcess Incoming Invoices
"Find unread emails with 'invoice' in the subject, download any PDF attachments"
Claude runs search → gets UIDs → downloads attachments per UID → marks as read.
Batch Notification Sending
"Send the report.pdf to the 5 team members on this list"
Claude iterates the list and calls smtp.js send for each recipient.
imap-smtp-email vs. Provider-Specific Skills
| Feature | imap-smtp-email | Gmail API skill | Resend/SendGrid |
|---|---|---|---|
| Provider compatibility | Any IMAP/SMTP | Gmail only | Send only |
| Chinese email providers | ✅ full support | ❌ | ❌ |
| Self-hosted mail servers | ✅ | ❌ | ❌ |
| OAuth required | ❌ | ✅ | API key |
| Read email | ✅ | ✅ | ❌ |
| Search & filter | ✅ | ✅ | ❌ |
| Download attachments | ✅ | ✅ | ❌ |
| Send with attachments | ✅ | ✅ | ✅ |
| Mark read/unread | ✅ | ✅ | ❌ |
How to Install
clawdbot install imap-smtp-emailThen run the setup wizard:
bash skillAssets/setup.shOr manually create .env with your IMAP and SMTP settings.
Practical Tips
-
Use app passwords, not account passwords. Gmail and most providers block standard password auth for IMAP/SMTP when 2FA is enabled. Generate an app-specific password from your account's security settings.
-
Start with
smtp.js test. Before building any workflow, verify the SMTP connection sends successfully. Connection failures (wrong port, TLS mismatch) are much easier to debug on a test email than in the middle of a workflow. -
Use
--recentfor monitoring workflows. When building a Claude workflow that checks email periodically,--recent 1hor--recent 30mis more reliable than tracking the last-checked timestamp yourself. -
Download attachments to a specific directory. Use
--dir /path/to/attachmentsconsistently rather than the default current directory. It keeps downloaded files organized and makes them easier for Claude to reference in subsequent steps. -
List mailboxes before searching non-INBOX folders. Folder names vary by provider.
list-mailboxesreveals the exact names for Sent, Spam, Archive, and custom folders before you search them. -
For 163.com and similar Chinese providers, authorization codes expire and must be renewed. If authentication fails after working previously, regenerate the authorization code in the web interface.
Considerations
- No event/push support: The skill polls via IMAP — it doesn't subscribe to server-push notifications. For real-time triggers, you'd need to run check on a schedule (cron or loop).
- Large inboxes can be slow: IMAP search performance depends on server implementation. Very large mailboxes may need
--limitto keep response times reasonable. - App passwords for Chinese providers: 163.com, 126.com, and similar providers use "authorization codes" rather than standard app passwords. The setup wizard guides you through this, but it's a common stumbling block.
- Attachment size limits: SMTP servers impose attachment size limits (typically 25MB for Gmail). Large files should be hosted externally and linked rather than attached.
- TLS configuration: Port 465 uses implicit SSL (
SMTP_SECURE=true); port 587 uses STARTTLS (SMTP_SECURE=false). Mismatching these is a common configuration error.
The Bigger Picture
The imap-smtp-email skill represents a philosophy that's increasingly common in ClawHub's most downloaded tools: build on open standards, not proprietary APIs. By using IMAP and SMTP directly, it covers the entire email ecosystem without the per-provider integration work that API-based approaches require.
For teams operating in environments with Chinese email providers, enterprise mail servers, or simply a mix of email accounts that don't fit neatly into any one vendor's integration — this is the email skill that actually works.
View the skill on ClawHub: imap-smtp-email