116 lines
2.5 KiB
Markdown

# 03. shazhou.work 邮箱
## 检查
```bash
cfg get MY_EMAIL
```
✅ 达标:返回 `你的名字@shazhou.work`,且能收发邮件
## 前置
- 已完成 01 (SSH 密钥对)
- 已完成 02 (cfg CLI)
## 安装
### 1. 安装 mcmail
```bash
npm install -g @shazhou/mcmail
```
### 2. 登录 Mailcheap
```bash
eval "$(cfg env)"
printf '%s\n%s\n' "$MAILCHEAP_USERNAME" "$MAILCHEAP_PASSWORD" | mcmail login
```
### 3. 检查邮箱是否已存在
```bash
mcmail accounts list
```
如果列表中已有你的 `xxx@shazhou.work` 账号且你知道密码,跳到第 5 步。
### 4. 创建/重建邮箱
邮箱名用你的身份名,如 `xiaonuo``xingyue`
```bash
mcmail accounts create 你的名字@shazhou.work --password "你的邮箱密码"
```
如果忘了密码,可以用管理员身份删掉重建:
```bash
echo "y" | mcmail accounts delete 你的名字@shazhou.work
mcmail accounts create 你的名字@shazhou.work --password "新密码"
```
### 5. 存入 cfg personal scope
```bash
cfg set MY_EMAIL 你的名字@shazhou.work
cfg set MY_EMAIL_PASSWORD '你的邮箱密码' --secret
```
### 6. 配置 himalaya(邮件 CLI)
安装 himalaya:
```bash
curl -sSL https://raw.githubusercontent.com/pimalaya/himalaya/master/install.sh | PREFIX=~/.local sh
```
创建 `~/.config/himalaya/config.toml`
```toml
[accounts.shazhou]
email = "你的名字@shazhou.work"
display-name = "你的显示名"
default = true
backend.type = "imap"
backend.host = "mail8.mymailcheap.com"
backend.port = 993
backend.encryption.type = "tls"
backend.login = "你的名字@shazhou.work"
backend.auth.type = "password"
backend.auth.cmd = "cfg get MY_EMAIL_PASSWORD"
message.send.backend.type = "smtp"
message.send.backend.host = "mail8.mymailcheap.com"
message.send.backend.port = 465
message.send.backend.encryption.type = "tls"
message.send.backend.login = "你的名字@shazhou.work"
message.send.backend.auth.type = "password"
message.send.backend.auth.cmd = "cfg get MY_EMAIL_PASSWORD"
```
密码通过 `cfg get MY_EMAIL_PASSWORD` 动态获取,不硬编码在配置里。
## 验证
给自己发一封邮件,确认能收到:
```bash
cat << EOF | himalaya message send
From: $(cfg get MY_EMAIL)
To: $(cfg get MY_EMAIL)
Subject: Onboard email test
Hello from $(hostname)!
EOF
# 等几秒后检查收件箱(可能在 Junk 里)
sleep 10
himalaya envelope list
himalaya envelope list --folder Junk
```
✅ 达标:Sent 里有发出的邮件,INBOX 或 Junk 里收到了邮件。