安装部署
通过 CLI 发送邮件
在 Mopheus CLI 中配置 SMTP 凭据,无需在 Linux 服务器上额外安装 mail / sendmail 工具即可发送邮件。
通过 CLI 发送邮件
mopheus email 子命令族允许在 CLI 中直接配置 SMTP 凭据并发送邮件,从而无需在 Linux 服务器上再单独部署 mail / sendmail 等命令行工具。SMTP 密码与 CLI token 一样,使用 tokencrypto envelope 加密后落盘,磁盘上不会保存明文。
总览
| 子命令 | 作用 |
|---|---|
mopheus email config | 为当前工作区(服务端持久化存储)或当前本地 profile 配置 SMTP 凭据。 |
mopheus email config get | 查看已配置的 SMTP 设置(密码脱敏,仅返回 hasPassword)。 |
mopheus email send | 通过工作区服务端发信中继代理或本地 profile 的 SMTP 服务器发送邮件。 |
工作区委托发信与本地模式
- 工作区模式:在关联 Mopheus 工作区的项目目录内运行或显式传入
--workspace <slug-or-id>时,SMTP 配置保存于服务端workspace.settings["email_smtp"],由主密钥经envcipher落盘加密。调用mopheus email send会直接代理至服务端接口(POST /api/v1/workspaces/:slug/email/send),无需将敏感凭据分发至各机器与守护进程。 - 本地模式:在工作区外运行或传入
--local时,SMTP 凭据使用 tokencrypto envelope 本地加密落盘,邮件直接由本机发起连接发送。
配置 SMTP 凭据
# 保存至工作区(服务端落盘加密,需具备工作区管理员或管理权限)
mopheus email config \
--workspace dev-space \
--host smtp.example.com \
--port 587 \
--user alice@example.com \
--password 'your-smtp-password' \
--sender alice@example.com \
--display-name "Alice Bot"
# 保存至本地 profile(隐式 TLS 模式)
mopheus email config \
--local \
--host smtp.example.com \
--port 465 \
--user alice@example.com \
--password 'your-smtp-password' \
--use-tls在交互式终端中省略 --password 时,CLI 会无回显地提示输入;在非交互模式(CI、脚本)中设置新密码时必须显式传入 --password。
重复运行 mopheus email config 时,未传入的字段会保留旧值,便于单独更新密码。
查看当前配置
# 查看工作区邮件配置(脱敏显示,不会泄露密码明文)
mopheus email config get --workspace dev-space
# 查看本地 profile 配置
mopheus email config get --local发送邮件
# 委托工作区服务端代发(自动识别工作区或使用 --workspace)
mopheus email send \
--workspace dev-space \
--to team@example.com \
--subject "构建成功" \
--body "所有单元测试与集成测试已全部通过。"
# 本机直连发送
mopheus email send \
--local \
--to alice@example.com \
--subject "状态报告" \
--body "一切正常。"
# 从文件读取正文
mopheus email send \
--to alice@example.com \
--cc bob@example.com \
--subject "FYI" \
--body-file ./message.txt
# 带附件(直接流式上传,避免 Base64 膨胀)
mopheus email send \
--to team@example.com \
--subject "周报" \
--body "详见附件 PDF。" \
--attachment ./report.pdf \
--attachment ./summary.csv--to、--cc、--bcc、--attachment 均为可重复标志,支持多个收件人 / 文件;--body 与 --body-file 互斥。
安全红线与配额防护
通过工作区发信时生效:
- 附件大小限制:单封邮件附件总上限 20MB,单个附件文件上限 15MB。超限时返回 HTTP 413(
EMAIL_ATTACHMENT_TOO_LARGE)。 - 频控与限流:工作区维度滑动窗口频控,默认突发 10 封/分钟、总上限 100 封/小时。超限时拒绝发信并返回 HTTP 429(
EMAIL_RATE_LIMITED)及Retry-After头指示重试等待秒数。 - CLI 在上传前执行本地预校验,防止大附件浪费带宽。
静态加密
- 工作区配置:SMTP 密码在服务端使用
envcipher(基于系统主密钥的 AES-GCM-256)加密落盘保存在 PostgreSQL 中,GET 查询接口永远不返回密文与明文(仅返回hasPassword: true)。 - 本地 Profile 配置:SMTP 密码以
emailPassword字段存储在~/.mopheus/config.json(或~/.mopheus/profiles/<name>/config.json)中,值为 tokencrypto envelope。密钥由(machineID, userID)经 Argon2id 派生,跨机器或跨 OS 用户无法解密磁盘上的值。
相关链接
mopheus config—— 通用 CLI 配置(server_url、token、workspace-id、embedding 等)。mopheus auth status—— 查看当前认证状态。