imap-smtp-email

Compare original and translation side by side

🇺🇸

Original

English
🇨🇳

Translation

Chinese

IMAP/SMTP Email

IMAP/SMTP Email

Read, search, and manage email via IMAP. Send email via SMTP.

通过IMAP读取、搜索和管理邮件,通过SMTP发送邮件。

Supported Providers

支持的服务商

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
Gmailimap.gmail.com993smtp.gmail.com587
Outlookoutlook.office365.com993smtp.office365.com587
QQ Mailimap.qq.com993smtp.qq.com587

服务商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
Gmailimap.gmail.com993smtp.gmail.com587
Outlookoutlook.office365.com993smtp.office365.com587
QQ Mailimap.qq.com993smtp.qq.com587

Configuration

配置

Setup

设置

bash
bash setup.sh
Config stored at
~/.config/imap-smtp-email/.env
bash
bash setup.sh
配置文件存储在
~/.config/imap-smtp-email/.env

Config File Format

配置文件格式

bash
undefined
bash
undefined

Default account (no prefix)

默认账户(无前缀)

IMAP_HOST=imap.gmail.com IMAP_PORT=993 IMAP_USER=your@email.com IMAP_PASS=your_password IMAP_TLS=true IMAP_MAILBOX=INBOX
SMTP_HOST=smtp.gmail.com SMTP_PORT=587 SMTP_SECURE=false SMTP_USER=your@email.com SMTP_PASS=your_password SMTP_FROM=your@email.com
IMAP_HOST=imap.gmail.com IMAP_PORT=993 IMAP_USER=your@email.com IMAP_PASS=your_password IMAP_TLS=true IMAP_MAILBOX=INBOX
SMTP_HOST=smtp.gmail.com SMTP_PORT=587 SMTP_SECURE=false SMTP_USER=your@email.com SMTP_PASS=your_password SMTP_FROM=your@email.com

File access whitelist

文件访问白名单

ALLOWED_READ_DIRS=/Downloads,/Documents ALLOWED_WRITE_DIRS=~/Downloads

---
ALLOWED_READ_DIRS=/Downloads,/Documents ALLOWED_WRITE_DIRS=~/Downloads

---

Multi-Account Support

多账户支持

Adding an Account

添加账户

bash
undefined
bash
undefined

Run setup and choose "Add a new account"

运行setup并选择"Add a new account"

bash setup.sh

Or manually add prefixed variables:

```bash
bash setup.sh

或者手动添加带前缀的变量:

```bash

Work account (WORK_ prefix)

工作账户(WORK_前缀)

WORK_IMAP_HOST=imap.company.com WORK_IMAP_PORT=993 WORK_IMAP_USER=me@company.com WORK_IMAP_PASS=password WORK_SMTP_HOST=smtp.company.com WORK_SMTP_PORT=587 WORK_SMTP_USER=me@company.com WORK_SMTP_PASS=password
undefined
WORK_IMAP_HOST=imap.company.com WORK_IMAP_PORT=993 WORK_IMAP_USER=me@company.com WORK_IMAP_PASS=password WORK_SMTP_HOST=smtp.company.com WORK_SMTP_PORT=587 WORK_SMTP_USER=me@company.com WORK_SMTP_PASS=password
undefined

Using a Named Account

使用指定账户

bash
undefined
bash
undefined

Use --account <name> before the command

在命令前使用 --account <name>

node scripts/imap.js --account work check node scripts/smtp.js --account work send --to foo@bar.com --subject Hi --body Hello

---
node scripts/imap.js --account work check node scripts/smtp.js --account work send --to foo@bar.com --subject Hi --body Hello

---

IMAP Commands (Receiving Email)

IMAP命令(接收邮件)

check — Check for New Emails

check — 检查新邮件

bash
node scripts/imap.js [--account <name>] check [--limit 10] [--mailbox INBOX] [--recent 2h]
Options:
  • --limit
    : Max results (default: 10)
  • --mailbox
    : Mailbox to check (default: INBOX)
  • --recent
    : Only show emails from last X time (e.g., 30m, 2h, 7d)
bash
node scripts/imap.js [--account <name>] check [--limit 10] [--mailbox INBOX] [--recent 2h]
选项:
  • --limit
    : 最大结果数(默认:10)
  • --mailbox
    : 要检查的邮箱(默认:INBOX)
  • --recent
    : 仅显示最近X时间内的邮件(例如:30m、2h、7d)

fetch — Fetch Full Email

fetch — 获取完整邮件

bash
node scripts/imap.js [--account <name>] fetch <uid> [--mailbox INBOX]
bash
node scripts/imap.js [--account <name>] fetch <uid> [--mailbox INBOX]

download — Download Attachments

download — 下载附件

bash
node scripts/imap.js [--account <name>] download <uid> [--dir <path>] [--file <filename>]
bash
node scripts/imap.js [--account <name>] download <uid> [--dir <path>] [--file <filename>]

search — Search Emails

search — 搜索邮件

bash
node scripts/imap.js [--account <name>] 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
  • --since <date>
    : After date (YYYY-MM-DD)
  • --before <date>
    : Before date (YYYY-MM-DD)
  • --limit <n>
    : Max results (default: 20)
bash
node scripts/imap.js [--account <name>] search [options]
选项:
  • --unseen
    : 仅显示未读邮件
  • --seen
    : 仅显示已读邮件
  • --from <email>
    : 发件人地址包含指定内容
  • --subject <text>
    : 主题包含指定内容
  • --recent <time>
    : 最近X时间内的邮件
  • --since <date>
    : 指定日期之后的邮件(格式:YYYY-MM-DD)
  • --before <date>
    : 指定日期之前的邮件(格式:YYYY-MM-DD)
  • --limit <n>
    : 最大结果数(默认:20)

mark-read / mark-unread

mark-read / mark-unread

bash
node scripts/imap.js [--account <name>] mark-read <uid> [uid2 uid3...]
node scripts/imap.js [--account <name>] mark-unread <uid> [uid2 uid3...]
bash
node scripts/imap.js [--account <name>] mark-read <uid> [uid2 uid3...]
node scripts/imap.js [--account <name>] mark-unread <uid> [uid2 uid3...]

list-mailboxes

list-mailboxes

bash
node scripts/imap.js [--account <name>] list-mailboxes
bash
node scripts/imap.js [--account <name>] list-mailboxes

list-accounts

list-accounts

bash
node scripts/imap.js list-accounts

bash
node scripts/imap.js list-accounts

SMTP Commands (Sending Email)

SMTP命令(发送邮件)

send — Send Email

send — 发送邮件

bash
node scripts/smtp.js [--account <name>] send --to <email> --subject <text> [options]
Required:
  • --to
    : Recipient (comma-separated for multiple)
  • --subject
    : Email subject
Optional:
  • --body
    : Plain text body
  • --html
    : Send body as HTML
  • --body-file
    : Read body from file
  • --html-file
    : Read HTML from file
  • --cc
    : CC recipients
  • --bcc
    : BCC recipients
  • --attach
    : Attachments (comma-separated)
  • --from
    : Override default sender
Examples:
bash
undefined
bash
node scripts/smtp.js [--account <name>] send --to <email> --subject <text> [options]
必填项:
  • --to
    : 收件人(多个收件人用逗号分隔)
  • --subject
    : 邮件主题
可选项:
  • --body
    : 纯文本邮件内容
  • --html
    : 将内容以HTML格式发送
  • --body-file
    : 从文件读取邮件内容
  • --html-file
    : 从文件读取HTML内容
  • --cc
    : 抄送收件人
  • --bcc
    : 密送收件人
  • --attach
    : 附件(多个附件用逗号分隔)
  • --from
    : 覆盖默认发件人
示例:
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 SMTP Connection

test — 测试SMTP连接

bash
node scripts/smtp.js [--account <name>] test

bash
node scripts/smtp.js [--account <name>] test

Important Notes

重要说明

Gmail

Gmail

163.com / 126.com

163.com / 126.com

  • Use authorization code (授权码), not account password
  • Enable IMAP/SMTP in web settings first

  • 使用 授权码(而非账户密码)
  • 需先在网页设置中启用IMAP/SMTP

Dependencies

依赖项

bash
npm install

bash
npm install

Security Notes

安全说明

  • Config stored at
    ~/.config/imap-smtp-email/.env
    with 600 permissions
  • File access whitelist limits where attachments can be saved
  • Never commit .env files to version control
  • 配置文件存储在
    ~/.config/imap-smtp-email/.env
    ,权限为600
  • 文件访问白名单限制了附件的保存路径
  • 切勿将.env文件提交到版本控制系统