IMAP/SMTP Email Tool
Read, search, and manage email via IMAP protocol. Send email via SMTP. Supports Gmail, Outlook, 163.com, vip.163.com, 126.com, vip.126.com, 188.com, vip.188.com, and any standard IMAP/SMTP server.
Configuration
Run the setup script to configure your email account:
CODEBLOCK0
Configuration is stored at ~/.config/imap-smtp-email/.env (survives skill updates). If no config is found there, the skill falls back to a .env file in the skill directory (for backward compatibility).
Config file format
CODEBLOCK1
Multi-Account
You can configure additional email accounts in the same config file. Each account uses a name prefix (uppercase) on all variables.
Adding an account
Run the setup script and choose "Add a new account":
CODEBLOCK2
Or manually add prefixed variables to ~/.config/imap-smtp-email/.env:
CODEBLOCK3
Using a named account
Add --account <name> before the command:
CODEBLOCK4
Without --account, the default (unprefixed) account is used.
Account name rules
- - Letters and digits only (e.g.,
work, 163, personal2) - Case-insensitive:
work and WORK refer to the same account - The prefix in
.env is always uppercase (e.g., WORK_IMAP_HOST) - INLINECODE12 and
ALLOWED_WRITE_DIRS are shared across all accounts (always unprefixed)
Common Email Servers
| Provider | IMAP Host | IMAP Port | SMTP Host | SMTP Port |
|---|
| 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 |
| vip.126.com | imap.vip.126.com | 993 | smtp.vip.126.com | 465 |
| 188.com | imap.188.com | 993 | smtp.188.com | 465 |
| vip.188.com | imap.vip.188.com | 993 | smtp.vip.188.com | 465 |
| yeah.net | imap.yeah.net | 993 | smtp.yeah.net | 465 |
| 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 |
Important for Gmail:
- - Gmail does not accept your regular account password
- You must generate an App Password: https://myaccount.google.com/apppasswords
- Use the generated 16-character App Password as
IMAP_PASS / INLINECODE15 - Requires Google Account with 2-Step Verification enabled
Important for 163.com:
- - Use authorization code (授权码), not account password
- Enable IMAP/SMTP in web settings first
IMAP Commands (Receiving Email)
check
Check for new/unread emails.
CODEBLOCK5
Options:
- -
--limit <n>: Max results (default: 10) - INLINECODE17 : Mailbox to check (default: INBOX)
- INLINECODE18 : Only show emails from last X time (e.g., 30m, 2h, 7d)
fetch
Fetch full email content by UID.
CODEBLOCK6
download
Download all attachments from an email, or a specific attachment.
CODEBLOCK7
Options:
- -
--mailbox <name>: Mailbox (default: INBOX) - INLINECODE20 : Output directory (default: current directory)
- INLINECODE21 : Download only the specified attachment (default: download all)
search
Search emails with filters.
CODEBLOCK8
mark-read / mark-unread
Mark message(s) as read or unread.
CODEBLOCK9
list-mailboxes
List all available mailboxes/folders.
CODEBLOCK10
list-accounts
List all configured email accounts.
CODEBLOCK11
Shows account name, email address, server addresses, and configuration status.
SMTP Commands (Sending Email)
send
Send email via SMTP.
CODEBLOCK12
Required:
- -
--to <email>: Recipient (comma-separated for multiple) - INLINECODE23 : Email subject, or INLINECODE24
Optional:
- -
--body <text>: Plain text body - INLINECODE26 : Send body as HTML
- INLINECODE27 : Read body from file
- INLINECODE28 : Read HTML from file
- INLINECODE29 : CC recipients
- INLINECODE30 : BCC recipients
- INLINECODE31 : Attachments (comma-separated)
- INLINECODE32 : Override default sender
Examples:
CODEBLOCK13
test
Test SMTP connection by sending a test email to yourself.
CODEBLOCK14
Dependencies
CODEBLOCK15
Security Notes
- - Configuration is stored at
~/.config/imap-smtp-email/.env with 600 permissions (owner read/write only) - 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
TLS/SSL errors:
- - Match
IMAP_TLS/SMTP_SECURE setting to server requirements - For self-signed certs: set
IMAP_REJECT_UNAUTHORIZED=false or INLINECODE38
IMAP/SMTP 电子邮件工具
通过IMAP协议读取、搜索和管理电子邮件。通过SMTP发送电子邮件。支持Gmail、Outlook、163.com、vip.163.com、126.com、vip.126.com、188.com、vip.188.com以及任何标准IMAP/SMTP服务器。
配置
运行设置脚本以配置您的电子邮件账户:
bash
bash setup.sh
配置存储在 ~/.config/imap-smtp-email/.env(技能更新后仍保留)。如果未找到配置,技能将回退到技能目录中的 .env 文件(用于向后兼容)。
配置文件格式
bash
默认账户(无前缀)
IMAP_HOST=imap.gmail.com
IMAP_PORT=993
IMAP_USER=your@email.com
IMAP
PASS=yourpassword
IMAP_TLS=true
IMAP
REJECTUNAUTHORIZED=true
IMAP_MAILBOX=INBOX
SMTP_HOST=smtp.gmail.com
SMTP_PORT=587
SMTP_SECURE=false
SMTP_USER=your@email.com
SMTPPASS=yourpassword
SMTP_FROM=your@email.com
SMTPREJECTUNAUTHORIZED=true
文件访问白名单(安全)
ALLOWED
READDIRS=~/Downloads,~/Documents
ALLOWED
WRITEDIRS=~/Downloads
多账户
您可以在同一配置文件中配置其他电子邮件账户。每个账户在所有变量上使用名称前缀(大写)。
添加账户
运行设置脚本并选择添加新账户:
bash
bash setup.sh
或手动将带前缀的变量添加到 ~/.config/imap-smtp-email/.env:
bash
工作账户(WORK_ 前缀)
WORK
IMAPHOST=imap.company.com
WORK
IMAPPORT=993
WORK
IMAPUSER=me@company.com
WORK
IMAPPASS=password
WORK
IMAPTLS=true
WORK
IMAPREJECT_UNAUTHORIZED=true
WORK
IMAPMAILBOX=INBOX
WORK
SMTPHOST=smtp.company.com
WORK
SMTPPORT=587
WORK
SMTPSECURE=false
WORK
SMTPUSER=me@company.com
WORK
SMTPPASS=password
WORK
SMTPFROM=me@company.com
WORK
SMTPREJECT_UNAUTHORIZED=true
使用命名账户
在命令前添加 --account <名称>:
bash
node scripts/imap.js --account work check
node scripts/smtp.js --account work send --to foo@bar.com --subject Hi --body Hello
不使用 --account 时,将使用默认(无前缀)账户。
账户名称规则
- - 仅限字母和数字(例如 work、163、personal2)
- 不区分大小写:work 和 WORK 指向同一账户
- .env 中的前缀始终大写(例如 WORKIMAPHOST)
- ALLOWEDREADDIRS 和 ALLOWEDWRITEDIRS 在所有账户间共享(始终无前缀)
常见电子邮件服务器
| 提供商 | IMAP 主机 | IMAP 端口 | SMTP 主机 | SMTP 端口 |
|---|
| 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 |
| vip.126.com | imap.vip.126.com | 993 | smtp.vip.126.com | 465 |
| 188.com | imap.188.com | 993 | smtp.188.com | 465 |
| vip.188.com | imap.vip.188.com | 993 | smtp.vip.188.com | 465 |
| yeah.net | imap.yeah.net | 993 | smtp.yeah.net | 465 |
| Gmail | imap.gmail.com | 993 | smtp.gmail.com | 587 |
| Outlook | outlook.office365.com | 993 | smtp.office365.com | 587 |
| QQ 邮箱 | imap.qq.com | 993 | smtp.qq.com | 587 |
Gmail 重要提示:
- - Gmail 不接受您的常规账户密码
- 您必须生成一个应用密码:https://myaccount.google.com/apppasswords
- 使用生成的16位应用密码作为 IMAPPASS / SMTPPASS
- 需要已启用两步验证的Google账户
163.com 重要提示:
- - 使用授权码,而非账户密码
- 先在网页设置中启用IMAP/SMTP
IMAP 命令(接收电子邮件)
check
检查新邮件/未读邮件。
bash
node scripts/imap.js [--account <名称>] check [--limit 10] [--mailbox INBOX] [--recent 2h]
选项:
- - --limit :最大结果数(默认:10)
- --mailbox <名称>:要检查的邮箱(默认:INBOX)
- --recent <时间>:仅显示最近X时间内的邮件(例如 30m、2h、7d)
fetch
通过UID获取完整邮件内容。
bash
node scripts/imap.js [--account <名称>] fetch [--mailbox INBOX]
download
下载邮件的所有附件或特定附件。
bash
node scripts/imap.js [--account <名称>] download [--mailbox INBOX] [--dir <路径>] [--file <文件名>]
选项:
- - --mailbox <名称>:邮箱(默认:INBOX)
- --dir <路径>:输出目录(默认:当前目录)
- --file <文件名>:仅下载指定附件(默认:下载全部)
search
使用筛选条件搜索邮件。
bash
node scripts/imap.js [--account <名称>] search [选项]
选项:
--unseen 仅未读邮件
--seen 仅已读邮件
--from <邮箱> 发件人地址包含
--subject <文本> 主题包含
--recent <时间> 最近X时间内(例如 30m、2h、7d)
--since <日期> 指定日期之后(YYYY-MM-DD)
--before <日期> 指定日期之前(YYYY-MM-DD)
--limit 最大结果数(默认:20)
--mailbox <名称> 要搜索的邮箱(默认:INBOX)
mark-read / mark-unread
将邮件标记为已读或未读。
bash
node scripts/imap.js [--account <名称>] mark-read [uid2 uid3...]
node scripts/imap.js [--account <名称>] mark-unread [uid2 uid3...]
list-mailboxes
列出所有可用的邮箱/文件夹。
bash
node scripts/imap.js [--account <名称>] list-mailboxes
list-accounts
列出所有已配置的电子邮件账户。
bash
node scripts/imap.js list-accounts
node scripts/smtp.js list-accounts
显示账户名称、电子邮件地址、服务器地址和配置状态。
SMTP 命令(发送电子邮件)
send
通过SMTP发送电子邮件。
bash
node scripts/smtp.js [--account <名称>] send --to <邮箱> --subject <文本> [选项]
必需:
- - --to <邮箱>:收件人(多个收件人用逗号分隔)
- --subject <文本>:邮件主题,或 --subject-file <文件>
可选:
- - --body <文本>:纯文本正文
- --html:将正文作为HTML发送
- --body-file <文件>:从文件读取正文
- --html-file <文件>:从文件读取HTML
- --cc <邮箱>:抄送收件人
- --bcc <邮箱>:密送收件人
- --attach <文件>:附件(多个用逗号分隔)
- --from <邮箱>:覆盖默认发件人
示例:
bash
简单文本邮件
node scripts/smtp.js send --to recipient@example.com --subject Hello --body World
HTML邮件
node scripts/smtp.js send --to recipient@example.com --subject Newsletter --html --body
Welcome
带附件的邮件
node scripts/smtp.js send --to recipient@example.com --subject Report --body Please find attached --attach report.pdf
多个收件人