Files
cloudflare_temp_email/vitepress-docs/docs/zh/guide/feature/config-smtp-proxy.md
Dream Hunter 8cf1150b15 feat: add STARTTLS support for SMTP proxy server (#876)
* feat: add STARTTLS support for SMTP proxy server

Add smtp_tls_cert and smtp_tls_key environment variables to enable
STARTTLS on the SMTP proxy server, matching existing IMAP TLS support.

Closes #249

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>

* test: add E2E tests for SMTP/IMAP STARTTLS

- Add smtp-proxy-tls service with self-signed certs in docker-compose
- Add smtp-tls.spec.ts: SMTP STARTTLS send plain/HTML/auth tests
- Add imap-tls.spec.ts: IMAP STARTTLS login/list/select/fetch tests
- Register smtp-proxy project in playwright.config.ts
- Wait for TLS proxy readiness in docker-entrypoint.sh

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>

* fix: enforce auth over TLS when STARTTLS is configured

- Set auth_require_tls conditionally based on tls_context presence
- Disable insecure SSLv2/SSLv3 protocols in TLS context

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>

* fix: replace cert-gen service with inline cert generation

The cert-gen one-shot container was exiting immediately after
generating certificates, triggering --abort-on-container-exit
and stopping all services before tests could run.

Replace with an entrypoint script in smtp-proxy-tls that generates
the self-signed cert before starting the proxy server.

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>

---------

Co-authored-by: Claude Opus 4.6 <noreply@anthropic.com>
2026-03-06 15:05:29 +08:00

2.9 KiB
Raw Blame History

搭建 SMTP IMAP 代理服务

::: warning 注意 如果你使用了 resend, 可直接使用 resendSMTP 服务,不需要使用此服务 :::

为什么需要 SMTP IMAP 代理服务

SMTP IMAP 的应用场景更加广泛

如何搭建 SMTP IMAP 代理服务

Local Run

cd smtp_proxy_server/
# 复制配置文件, 并修改配置文件
# 你的 worker 地址proxy_url=https://temp-email-api.xxx.xxx
# 你的 SMTP 服务端口port=8025
cp .env.example .env
python3 -m venv venv
./venv/bin/python3 -m pip install -r requirements.txt
./venv/bin/python3 main.py

Docker Run

cd smtp_proxy_server/
docker-compose up -d

修改 docker-compose.yaml 中的环境变量, 注意选择合适的 tag

proxy_urlworker 的 URL 地址

services:
  smtp_proxy_server:
    image: ghcr.io/dreamhunter2333/cloudflare_temp_email/smtp_proxy_server:latest
    # build:
    #   context: .
    #   dockerfile: dockerfile
    container_name: "smtp_proxy_server"
    ports:
      - "8025:8025"
      - "11143:11143"
    environment:
      - proxy_url=https://temp-email-api.xxx.xxx
      - port=8025
      - imap_port=11143

环境变量

变量 默认值 说明
proxy_url http://localhost:8787 Worker 后端 URL
port 8025 SMTP 端口
imap_port 11143 IMAP 端口
smtp_tls_cert SMTP TLS 证书文件路径PEM配置后启用 STARTTLS
smtp_tls_key SMTP TLS 私钥文件路径PEM
imap_tls_cert IMAP TLS 证书文件路径PEM配置后启用 STARTTLS
imap_tls_key IMAP TLS 私钥文件路径PEM
imap_cache_size 500 每个邮箱的消息缓存上限
imap_http_timeout 30.0 后端 HTTP 请求超时时间(秒)

启用 STARTTLS

分别配置 SMTP 和 IMAP 的 TLS 证书环境变量后,对应服务会自动支持 STARTTLS。SMTP 和 IMAP 可以使用同一套证书。

# .env 示例
smtp_tls_cert=/path/to/cert.pem
smtp_tls_key=/path/to/key.pem
imap_tls_cert=/path/to/cert.pem
imap_tls_key=/path/to/key.pem

Docker Compose 中配置:

environment:
  - smtp_tls_cert=/certs/cert.pem
  - smtp_tls_key=/certs/key.pem
  - imap_tls_cert=/certs/cert.pem
  - imap_tls_key=/certs/key.pem
volumes:
  - ./certs:/certs:ro

IMAP 登录方式

支持两种登录方式:

方式 用户名 密码 说明
JWT 凭证 邮箱地址 JWT token 从前端获取的地址凭证,直接认证
地址+密码 邮箱地址 地址密码 通过后端 /api/address_login 验证

系统会自动识别密码格式:以 eyJ 开头的三段式字符串视为 JWT其他视为密码并调用后端验证。

使用 Thunderbird 登录

下载 Thunderbird

密码填写 邮箱地址凭证邮箱地址密码

imap