imap-smtp-email

Compare original and translation side by side

🇺🇸

Original

English
🇨🇳

Translation

Chinese

IMAP/SMTP Email Tool

IMAP/SMTP 邮件工具

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.
通过IMAP协议读取、搜索和管理邮件,通过SMTP协议发送邮件。支持Gmail、Outlook、163.com、vip.163.com、126.com、vip.126.com、188.com、vip.188.com以及任何标准IMAP/SMTP服务器。

Configuration

配置说明

Create
.env
in the skill folder or set environment variables:
bash
undefined
在skill目录下创建
.env
文件,或设置环境变量:
bash
undefined

IMAP Configuration (receiving email)

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
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 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
undefined
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
undefined

Common Email Servers

常见邮件服务器参数

ProviderIMAP HostIMAP PortSMTP HostSMTP Port
163.comimap.163.com993smtp.163.com465
vip.163.comimap.vip.163.com993smtp.vip.163.com465
126.comimap.126.com993smtp.126.com465
vip.126.comimap.vip.126.com993smtp.vip.126.com465
188.comimap.188.com993smtp.188.com465
vip.188.comimap.vip.188.com993smtp.vip.188.com465
yeah.netimap.yeah.net993smtp.yeah.net465
Gmailimap.gmail.com993smtp.gmail.com587
Outlookoutlook.office365.com993smtp.office365.com587
QQ Mailimap.qq.com993smtp.qq.com587
Important for 163.com:
  • Use authorization code (授权码), not account password
  • Enable IMAP/SMTP in web settings first
服务商IMAP 服务器IMAP 端口SMTP 服务器SMTP 端口
163.comimap.163.com993smtp.163.com465
vip.163.comimap.vip.163.com993smtp.vip.163.com465
126.comimap.126.com993smtp.126.com465
vip.126.comimap.vip.126.com993smtp.vip.126.com465
188.comimap.188.com993smtp.188.com465
vip.188.comimap.vip.188.com993smtp.vip.188.com465
yeah.netimap.yeah.net993smtp.yeah.net465
Gmailimap.gmail.com993smtp.gmail.com587
Outlookoutlook.office365.com993smtp.office365.com587
QQ 邮箱imap.qq.com993smtp.qq.com587
163.com用户重要提示:
  • 使用授权码,而非账户密码
  • 需先在网页设置中开启IMAP/SMTP功能

IMAP Commands (Receiving Email)

IMAP命令(接收邮件)

check

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)
检查新邮件/未读邮件。
bash
node scripts/imap.js check [--limit 10] [--mailbox INBOX] [--recent 2h]
选项说明:
  • --limit <n>
    :最大结果数(默认:10)
  • --mailbox <name>
    :要检查的邮箱(默认:INBOX)
  • --recent <time>
    :仅显示最近X时间内的邮件(例如:30m、2h、7d)

fetch

fetch

Fetch full email content by UID.
bash
node scripts/imap.js fetch <uid> [--mailbox INBOX]
通过UID获取完整邮件内容。
bash
node scripts/imap.js fetch <uid> [--mailbox INBOX]

download

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)
下载某封邮件的所有附件,或指定附件。
bash
node scripts/imap.js download <uid> [--mailbox INBOX] [--dir <path>] [--file <filename>]
选项说明:
  • --mailbox <name>
    :目标邮箱(默认:INBOX)
  • --dir <path>
    :输出目录(默认:当前目录)
  • --file <filename>
    :仅下载指定附件(默认:下载所有附件)

search

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)
通过筛选条件搜索邮件。
bash
node scripts/imap.js search [options]

Options:
  --unseen           仅显示未读邮件
  --seen             仅显示已读邮件
  --from <email>     发件人地址包含指定内容
  --subject <text>   主题包含指定内容
  --recent <time>    最近X时间内的邮件(例如:30m、2h、7d)
  --since <date>     指定日期之后的邮件(格式:YYYY-MM-DD)
  --before <date>    指定日期之前的邮件(格式:YYYY-MM-DD)
  --limit <n>        最大结果数(默认:20)
  --mailbox <name>   要搜索的邮箱(默认:INBOX)

mark-read / mark-unread

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...]
将邮件标记为已读或未读。
bash
node scripts/imap.js mark-read <uid> [uid2 uid3...]
node scripts/imap.js mark-unread <uid> [uid2 uid3...]

list-mailboxes

list-mailboxes

List all available mailboxes/folders.
bash
node scripts/imap.js list-mailboxes
列出所有可用的邮箱/文件夹。
bash
node scripts/imap.js list-mailboxes

SMTP Commands (Sending Email)

SMTP命令(发送邮件)

send

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
undefined
通过SMTP发送邮件。
bash
node scripts/smtp.js send --to <email> --subject <text> [options]
必填参数:
  • --to <email>
    :收件人地址(多个收件人用逗号分隔)
  • --subject <text>
    :邮件主题,或使用
    --subject-file <file>
    从文件读取主题
可选参数:
  • --body <text>
    :纯文本邮件正文
  • --html
    :将正文以HTML格式发送
  • --body-file <file>
    :从文件读取邮件正文
  • --html-file <file>
    :从文件读取HTML内容
  • --cc <email>
    :抄送收件人
  • --bcc <email>
    :密送收件人
  • --attach <file>
    :附件(多个附件用逗号分隔)
  • --from <email>
    :覆盖默认发件人地址
示例:
bash
undefined

Simple text email

简单文本邮件

node scripts/smtp.js send --to recipient@example.com --subject "Hello" --body "World"
node scripts/smtp.js send --to recipient@example.com --subject "Hello" --body "World"

HTML email

HTML格式邮件

node scripts/smtp.js send --to recipient@example.com --subject "Newsletter" --html --body "<h1>Welcome</h1>"
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
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"
undefined
node scripts/smtp.js send --to "a@example.com,b@example.com" --cc "c@example.com" --subject "Update" --body "Team update"
undefined

test

test

Test SMTP connection by sending a test email to yourself.
bash
node scripts/smtp.js test
通过发送测试邮件给自己来验证SMTP连接。
bash
node scripts/smtp.js test

Dependencies

依赖安装

bash
npm install
bash
npm install

Security Notes

安全注意事项

  • Store credentials in
    .env
    (add to
    .gitignore
    )
  • For Gmail: use App Password if 2FA is enabled
  • For 163.com: use authorization code (授权码), not account password
  • 将凭据存储在
    .env
    文件中(需将该文件添加到
    .gitignore
  • 对于Gmail:如果开启了双因素认证,请使用应用专用密码
  • 对于163.com:使用授权码,而非账户密码

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: use App Password if 2FA enabled
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
连接超时:
  • 确认服务器正常运行且可访问
  • 检查服务器地址/端口配置是否正确
认证失败:
  • 确认用户名(通常为完整邮箱地址)正确
  • 检查密码是否正确
  • 对于163.com:使用授权码,而非账户密码
  • 对于Gmail:如果开启了双因素认证,请使用应用专用密码
TLS/SSL错误:
  • 确保
    IMAP_TLS
    /
    SMTP_SECURE
    设置与服务器要求匹配
  • 对于自签名证书:将
    IMAP_REJECT_UNAUTHORIZED
    SMTP_REJECT_UNAUTHORIZED
    设置为
    false