qwen_agent/skills/imap-smtp-email/SKILL.md
2026-03-11 16:08:41 +08:00

257 lines
8.8 KiB
Markdown

---
name: imap-smtp-email
description: 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 standard IMAP/SMTP server.
metadata:
openclaw:
emoji: "📧"
requires:
env:
- IMAP_HOST
- IMAP_USER
- IMAP_PASS
- SMTP_HOST
- SMTP_USER
- SMTP_PASS
bins:
- node
- npm
primaryEnv: SMTP_PASS
---
# IMAP/SMTP Email Tool
Read, search, and manage email via IMAP protocol. Send email via SMTP. Works with any standard IMAP/SMTP server.
## Configuration
Create `.env` in the skill folder or set environment variables:
```bash
# IMAP Configuration (receiving email)
IMAP_HOST=imap.gmail.com # Server hostname
IMAP_PORT=993 # Server port
IMAP_USER=your@email.com
IMAP_PASS=your_password
IMAP_TLS=true # Use TLS/SSL connection
IMAP_REJECT_UNAUTHORIZED=true # Set to false for self-signed certs
IMAP_MAILBOX=INBOX # Default mailbox
# SMTP Configuration (sending email)
SMTP_HOST=smtp.gmail.com # SMTP server hostname
SMTP_PORT=587 # SMTP port (587 for STARTTLS, 465 for SSL)
SMTP_SECURE=false # true for SSL (465), false for STARTTLS (587)
SMTP_USER=your@gmail.com # Your email address
SMTP_PASS=your_password # Your password or app password
SMTP_FROM=your@gmail.com # Default sender email (optional)
SMTP_REJECT_UNAUTHORIZED=true # Set to false for self-signed certs
```
## Common Email Servers
### Global Providers
| Provider | IMAP Host | IMAP Port | SMTP Host | SMTP Port | SMTP Secure |
|----------|-----------|-----------|-----------|-----------|-------------|
| Gmail | imap.gmail.com | 993 | smtp.gmail.com | 587 | false |
| Outlook / Hotmail | outlook.office365.com | 993 | smtp.office365.com | 587 | false |
| Yahoo Mail | imap.mail.yahoo.com | 993 | smtp.mail.yahoo.com | 465 | true |
| iCloud Mail | imap.mail.me.com | 993 | smtp.mail.me.com | 587 | false |
| Zoho Mail | imap.zoho.com | 993 | smtp.zoho.com | 465 | true |
| Fastmail | imap.fastmail.com | 993 | smtp.fastmail.com | 465 | true |
| AOL Mail | imap.aol.com | 993 | smtp.aol.com | 465 | true |
| GMX Mail | imap.gmx.com | 993 | mail.gmx.com | 587 | false |
| ProtonMail (Bridge) | 127.0.0.1 | 1143 | 127.0.0.1 | 1025 | false |
### Japan Providers (日本のメールサービス)
| Provider | IMAP Host | IMAP Port | SMTP Host | SMTP Port | SMTP Secure |
|----------|-----------|-----------|-----------|-----------|-------------|
| Yahoo! JAPAN | imap.mail.yahoo.co.jp | 993 | smtp.mail.yahoo.co.jp | 465 | true |
| OCN | imap.ocn.ne.jp | 993 | smtp.ocn.ne.jp | 465 | true |
| BIGLOBE | mail.biglobe.ne.jp | 993 | mail.biglobe.ne.jp | 465 | true |
| @nifty | imap.nifty.com | 993 | smtp.nifty.com | 587 | false |
| plala | imap.plala.or.jp | 993 | secure.plala.or.jp | 465 | true |
| So-net | imap.so-net.ne.jp | 993 | mail.so-net.ne.jp | 587 | false |
| au Mail (@au.com) | imap.au.com | 993 | smtp.au.com | 465 | true |
| Excite Mail | imap.excite.co.jp | 993 | smtp.excite.co.jp | 587 | false |
| Infoseek Mail | imap.infoseek.jp | 993 | smtp.infoseek.jp | 587 | false |
| SAKURA Internet | imap.sakura.ne.jp | 993 | smtp.sakura.ne.jp | 587 | false |
### China Providers (中国邮箱)
| Provider | IMAP Host | IMAP Port | SMTP Host | SMTP Port | SMTP Secure |
|----------|-----------|-----------|-----------|-----------|-------------|
| 163.com | imap.163.com | 993 | smtp.163.com | 465 | true |
| vip.163.com | imap.vip.163.com | 993 | smtp.vip.163.com | 465 | true |
| 126.com | imap.126.com | 993 | smtp.126.com | 465 | true |
| vip.126.com | imap.vip.126.com | 993 | smtp.vip.126.com | 465 | true |
| 188.com | imap.188.com | 993 | smtp.188.com | 465 | true |
| vip.188.com | imap.vip.188.com | 993 | smtp.vip.188.com | 465 | true |
| yeah.net | imap.yeah.net | 993 | smtp.yeah.net | 465 | true |
| QQ Mail | imap.qq.com | 993 | smtp.qq.com | 587 | false |
### Provider-specific Notes
**Gmail:**
- Does **not** accept regular account password
- Must generate an **App Password**: https://myaccount.google.com/apppasswords
- Requires Google Account with 2-Step Verification enabled
**iCloud Mail:**
- Requires an **App-Specific Password**: https://appleid.apple.com/account/manage
- Enable "Access IMAP" in iCloud Mail settings
**Yahoo! JAPAN (Yahoo! JAPANメール):**
- Use **App Password** (アプリパスワード), not account password
- Enable IMAP access in Yahoo! JAPAN Mail settings (設定 → IMAP/POP/SMTPアクセス)
**163.com / 126.com / yeah.net:**
- Use **authorization code** (授权码), not account password
- Enable IMAP/SMTP in web settings first
**OCN / BIGLOBE / @nifty / plala / So-net:**
- Some ISPs require you to enable IMAP/SMTP access first from web settings
- Use the mail password provided by the ISP (may differ from login password)
## IMAP Commands (Receiving Email)
### check
Check for new/unread emails.
```bash
node scripts/imap.js check [--limit 10] [--mailbox INBOX] [--recent 2h]
```
Options:
- `--limit <n>`: Max results (default: 10)
- `--mailbox <name>`: Mailbox to check (default: INBOX)
- `--recent <time>`: Only show emails from last X time (e.g., 30m, 2h, 7d)
### fetch
Fetch full email content by UID.
```bash
node scripts/imap.js fetch <uid> [--mailbox INBOX]
```
### download
Download all attachments from an email, or a specific attachment.
```bash
node scripts/imap.js download <uid> [--mailbox INBOX] [--dir <path>] [--file <filename>]
```
Options:
- `--mailbox <name>`: Mailbox (default: INBOX)
- `--dir <path>`: Output directory (default: current directory)
- `--file <filename>`: Download only the specified attachment (default: download all)
### search
Search emails with filters.
```bash
node scripts/imap.js search [options]
Options:
--unseen Only unread messages
--seen Only read messages
--from <email> From address contains
--subject <text> Subject contains
--recent <time> From last X time (e.g., 30m, 2h, 7d)
--since <date> After date (YYYY-MM-DD)
--before <date> Before date (YYYY-MM-DD)
--limit <n> Max results (default: 20)
--mailbox <name> Mailbox to search (default: INBOX)
```
### mark-read / mark-unread
Mark message(s) as read or unread.
```bash
node scripts/imap.js mark-read <uid> [uid2 uid3...]
node scripts/imap.js mark-unread <uid> [uid2 uid3...]
```
### list-mailboxes
List all available mailboxes/folders.
```bash
node scripts/imap.js list-mailboxes
```
## SMTP Commands (Sending Email)
### send
Send email via SMTP.
```bash
node scripts/smtp.js send --to <email> --subject <text> [options]
```
**Required:**
- `--to <email>`: Recipient (comma-separated for multiple)
- `--subject <text>`: Email subject, or `--subject-file <file>`
**Optional:**
- `--body <text>`: Plain text body
- `--html`: Send body as HTML
- `--body-file <file>`: Read body from file
- `--html-file <file>`: Read HTML from file
- `--cc <email>`: CC recipients
- `--bcc <email>`: BCC recipients
- `--attach <file>`: Attachments (comma-separated)
- `--from <email>`: Override default sender
**Examples:**
```bash
# 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 "Newsletter" --html --body "<h1>Welcome</h1>"
# Email with attachment
node scripts/smtp.js send --to recipient@example.com --subject "Report" --body "Please find attached" --attach report.pdf
# Multiple recipients
node scripts/smtp.js send --to "a@example.com,b@example.com" --cc "c@example.com" --subject "Update" --body "Team update"
```
### test
Test SMTP connection by sending a test email to yourself.
```bash
node scripts/smtp.js test
```
## Dependencies
```bash
npm install
```
## Security Notes
- Store credentials in `.env` (add to `.gitignore`)
- **Gmail**: regular password is rejected — generate an App Password at https://myaccount.google.com/apppasswords
- For 163.com: use authorization code (授权码), not account password
## Troubleshooting
**Connection timeout:**
- Verify server is running and accessible
- Check host/port configuration
**Authentication failed:**
- Verify username (usually full email address)
- Check password is correct
- For 163.com: use authorization code, not account password
- For Gmail: regular password won't work — generate an App Password at https://myaccount.google.com/apppasswords
- For iCloud: use App-Specific Password from https://appleid.apple.com/account/manage
- For Yahoo! JAPAN: use App Password (アプリパスワード)
- For Japanese ISPs (OCN, BIGLOBE, etc.): use the mail-specific password from your ISP
**TLS/SSL errors:**
- Match `IMAP_TLS`/`SMTP_SECURE` setting to server requirements
- For self-signed certs: set `IMAP_REJECT_UNAUTHORIZED=false` or `SMTP_REJECT_UNAUTHORIZED=false`