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>
This commit is contained in:
Dream Hunter
2026-03-06 15:05:29 +08:00
committed by GitHub
co-authored by Claude Opus 4.6
parent 8341cae28f
commit 8cf1150b15
14 changed files with 307 additions and 11 deletions
@@ -58,17 +58,21 @@ services:
| `proxy_url` | `http://localhost:8787` | Worker 后端 URL |
| `port` | `8025` | SMTP 端口 |
| `imap_port` | `11143` | IMAP 端口 |
| `imap_tls_cert` | 空 | TLS 证书文件路径(PEM),配置后启用 STARTTLS |
| `imap_tls_key` | 空 | TLS 私钥文件路径(PEM |
| `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
配置 `imap_tls_cert``imap_tls_key` 环境变量后,IMAP 服务会自动支持 STARTTLS。
分别配置 SMTP 和 IMAP 的 TLS 证书环境变量后,对应服务会自动支持 STARTTLS。SMTP 和 IMAP 可以使用同一套证书。
```bash
# .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
```
@@ -77,6 +81,8 @@ Docker Compose 中配置:
```yaml
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: