weavmail is a command-line email client designed for AI agents. Use it to read, send, reply to, and organize emails
Setup
Install once before first use:
CODEBLOCK0
Configure an account (named default):
CODEBLOCK1
INLINECODE2 and --password set both IMAP and SMTP credentials at once. The account name defaults to default and can be omitted from all subsequent commands.
Each option can be updated independently — only the options you pass are changed, everything else is preserved. For example, to update just the password:
CODEBLOCK2
INLINECODE5 is a comma-separated list of email addresses that are authorized as senders for this account (e.g. --addresses you@example.com,alias@example.com). All addresses listed here can be used as the --from address when sending mail.
To view the current configuration of an account, run account config without any options:
CODEBLOCK3
After Configuring an Account
After any account is configured, always run the following automatically:
CODEBLOCK4
Inspect the output and identify the Sent and Trash folders (names vary by provider, e.g. Sent, Sent Messages, [Gmail]/Sent Mail, Trash, Deleted Messages, [Gmail]/Trash). Then save them to the account config:
CODEBLOCK5
All three fields are optional — if any cannot be identified with confidence, skip it. They do not affect other functionality when unset.
Sync Inbox
Fetch the latest emails from INBOX and save them as local Markdown files:
CODEBLOCK6
Options:
- -
--account NAMES — comma-separated account names to sync (default: all configured accounts) - INLINECODE16 — sync a different folder (default:
INBOX) - INLINECODE18 — number of most-recent messages to fetch (default:
10)
Each email is saved to ./mails/<account>_<mailbox>/<uid>.md with YAML front matter:
CODEBLOCK7
Always sync before reading mail. After syncing, read .md files directly — the body starts after the second ---.
List Mailboxes
List all available IMAP folders for the account:
CODEBLOCK8
Use this to discover exact folder names before syncing a non-INBOX mailbox. Folder names are case-sensitive.
Move a Mail
Move an email to another folder, then automatically sync the source mailbox:
CODEBLOCK9
The source mailbox is synced after the move — the local file will be deleted automatically.
To delete a mail, move it to the Trash folder. The exact name varies by provider (e.g. Trash, Deleted Messages, [Gmail]/Trash). Use weavmail mailbox to find the correct name first.
Trash a Mail
Move one or more emails to the account's trash mailbox, then automatically sync the source mailbox:
CODEBLOCK10
Multiple MAIL_FILE arguments can be passed for batch operations. The trash mailbox is read from each mail's account --trash-mailbox configuration. An error is raised if --trash-mailbox is not configured for the account.
The source mailbox is synced after the move — the local file will be deleted automatically.
Archive a Mail
Move one or more emails to the account's archive mailbox, then automatically sync the source mailbox:
CODEBLOCK11
Multiple MAIL_FILE arguments can be passed for batch operations. The archive mailbox is read from each mail's account --archive-mailbox configuration. An error is raised if --archive-mailbox is not configured for the account.
The source mailbox is synced after the move — the local file will be deleted automatically.
Send a Mail
Write the body to a file, then send:
CODEBLOCK12
INLINECODE33 , --cc, and --bcc are all repeatable for multiple recipients. --from defaults to the first configured address.
Reply to a Mail
CODEBLOCK13
In reply mode, subject, to, and from are all inferred from the original mail's front matter. The original body is quoted and appended. In-Reply-To and References headers are set automatically. Override any of them with explicit options if needed.
Notes
- - Never guess UIDs. Always sync first, then reference files from the output.
- Mailbox names are case-sensitive. Use
weavmail mailbox to list exact names. - The
mailbox field in front matter stores the original unescaped name (e.g. INBOX/Sent); the directory path uses _ as a separator. - Front matter is authoritative for metadata — always read it from the
.md file. - All commands support
--help for full option details, e.g. weavmail sync --help.
Multiple Accounts
Configure additional accounts by providing a name:
CODEBLOCK14
Then pass --account to any command to target that account:
CODEBLOCK15
INLINECODE50 without --account syncs all configured accounts automatically.
For move and send --reply, the account is read from the mail file's front matter — you may pass --account as a safeguard: if it doesn't match the account in the front matter, the command will exit with an error. For trash and archive, the account is always read from each mail file's front matter (no --account option).
weavmail 是一个专为AI代理设计的命令行电子邮件客户端。用于读取、发送、回复和组织邮件
设置
首次使用前安装一次:
bash
uv tool install weavmail
配置一个账户(命名为 default):
bash
weavmail account config \
--imap-host imap.example.com \
--smtp-host smtp.example.com \
--username you@example.com \
--password your-app-password \
--addresses you@example.com
--username 和 --password 同时设置IMAP和SMTP凭据。账户名称默认为 default,在后续所有命令中可以省略。
每个选项可以独立更新——只更改您传递的选项,其他所有内容保持不变。例如,仅更新密码:
bash
weavmail account config --password new-password
--addresses 是一个逗号分隔的电子邮件地址列表,这些地址被授权为该账户的发件人(例如 --addresses you@example.com,alias@example.com)。此处列出的所有地址在发送邮件时都可以用作 --from 地址。
要查看账户的当前配置,运行不带任何选项的 account config:
bash
weavmail account config # 显示默认账户
weavmail account config work # 显示名为work的账户
配置账户后
配置任何账户后,始终自动运行以下命令:
bash
weavmail mailbox
检查输出并识别已发送和垃圾箱文件夹(名称因提供商而异,例如 Sent、Sent Messages、[Gmail]/Sent Mail、Trash、Deleted Messages、[Gmail]/Trash)。然后将它们保存到账户配置中:
bash
weavmail account config --sent-mailbox Sent --trash-mailbox Trash --archive-mailbox Archive
所有三个字段都是可选的——如果无法确定任何字段,则跳过。未设置时不影响其他功能。
同步收件箱
从收件箱获取最新邮件并将其保存为本地Markdown文件:
bash
weavmail sync
选项:
- - --account NAMES — 要同步的逗号分隔的账户名称(默认:所有已配置的账户)
- --mailbox FOLDER — 同步不同的文件夹(默认:INBOX)
- --limit N — 要获取的最新消息数量(默认:10)
每封邮件保存到 ./mails/_/.md,带有YAML前置元数据:
yaml
uid: 12345
account: default
mailbox: INBOX
subject: Hello there
from: sender@example.com
to:
cc: []
date: 01 Jan 2026 12:00:00 +0000
flags: []
邮件正文在此...
在读取邮件之前始终先同步。 同步后,直接读取 .md 文件——正文从第二个 --- 之后开始。
列出邮箱
列出账户的所有可用IMAP文件夹:
bash
weavmail mailbox
在同步非收件箱邮箱之前,使用此命令发现确切的文件夹名称。文件夹名称区分大小写。
移动邮件
将邮件移动到另一个文件夹,然后自动同步源邮箱:
bash
weavmail move mails/default_INBOX/12345.md Archive
移动后源邮箱会同步——本地文件将自动删除。
要删除邮件,将其移动到垃圾箱文件夹。确切名称因提供商而异(例如 Trash、Deleted Messages、[Gmail]/Trash)。首先使用 weavmail mailbox 查找正确的名称。
删除邮件
将一封或多封邮件移动到账户的垃圾箱邮箱,然后自动同步源邮箱:
bash
weavmail trash mails/default_INBOX/12345.md
weavmail trash mails/defaultINBOX/12345.md mails/defaultINBOX/67890.md
可以传递多个 MAIL_FILE 参数进行批量操作。垃圾箱邮箱从每封邮件的账户 --trash-mailbox 配置中读取。如果账户未配置 --trash-mailbox,则会报错。
移动后源邮箱会同步——本地文件将自动删除。
归档邮件
将一封或多封邮件移动到账户的归档邮箱,然后自动同步源邮箱:
bash
weavmail archive mails/default_INBOX/12345.md
weavmail archive mails/defaultINBOX/12345.md mails/defaultINBOX/67890.md
可以传递多个 MAIL_FILE 参数进行批量操作。归档邮箱从每封邮件的账户 --archive-mailbox 配置中读取。如果账户未配置 --archive-mailbox,则会报错。
移动后源邮箱会同步——本地文件将自动删除。
发送邮件
将正文写入文件,然后发送:
bash
cat > /tmp/body.txt << EOF
您的消息在此。
EOF
weavmail send \
--to recipient@example.com \
--subject Hello \
--content /tmp/body.txt
--to、--cc 和 --bcc 对于多个收件人都可以重复使用。--from 默认为第一个配置的地址。
回复邮件
bash
weavmail send \
--reply mails/default_INBOX/12345.md \
--content /tmp/reply.txt
在回复模式下,subject、to 和 from 都从原始邮件的前置元数据中推断。原始正文被引用并附加。In-Reply-To 和 References 标头自动设置。如果需要,可以使用显式选项覆盖其中任何一个。
注意事项
- - 切勿猜测UID。 始终先同步,然后引用输出中的文件。
- 邮箱名称区分大小写。 使用 weavmail mailbox 列出确切的名称。
- 前置元数据中的 mailbox 字段存储原始的未转义名称(例如 INBOX/Sent);目录路径使用 _ 作为分隔符。
- 前置元数据是元数据的权威来源——始终从 .md 文件中读取。
- 所有命令都支持 --help 查看完整选项详情,例如 weavmail sync --help。
多账户
通过提供名称来配置其他账户:
bash
weavmail account config work \
--imap-host imap.work.com \
--smtp-host smtp.work.com \
--username you@work.com \
--password your-password \
--addresses you@work.com
然后将 --account 传递给任何命令以针对该账户:
bash
weavmail sync --account work
weavmail sync --account work,personal # 同时同步多个账户
weavmail mailbox --account work
weavmail send --account work --to someone@example.com --subject Hi --content /tmp/body.txt
不带 --account 的 weavmail sync 会自动同步所有已配置的账户。
对于 move 和 send --reply,账户从邮件文件的前置元数据中读取——您可以传递 --account 作为安全措施:如果它与前置元数据中的账户不匹配,命令将以错误退出。对于 trash 和 archive,账户始终从每个邮件文件的前置元数据中读取(没有 --account 选项)。