feat(email): 初始化自建邮箱 MVP
- 新增 Go + SQLite 后端,支持登录、域名、邮箱、别名、联系人、规则、统计与邮件收发。 - 新增 Webmail 前端,支持多邮箱切换、邮件列表/阅读/写信、附件、搜索、主题切换与个人中心。 - 新增 Docker Compose 部署骨架,补充 Postfix、Dovecot、OpenDKIM、Nginx 配置与部署说明。
This commit is contained in:
@@ -0,0 +1,14 @@
|
||||
LANQIN_PUBLIC_HOSTNAME=mail.example.com
|
||||
LANQIN_PUBLIC_BASE_URL=https://mail.example.com
|
||||
LANQIN_ADMIN_EMAIL=admin@example.com
|
||||
LANQIN_ADMIN_PASSWORD=ChangeMe123!
|
||||
LANQIN_DATA_DIR=/data
|
||||
LANQIN_DB_PATH=/data/lanqin.db
|
||||
LANQIN_ADDR=:8080
|
||||
LANQIN_ALLOW_INSECURE_HTTP=false
|
||||
LANQIN_SMTP_HOST=postfix
|
||||
LANQIN_SMTP_PORT=25
|
||||
LANQIN_SMTP_REQUIRE_TLS=false
|
||||
LANQIN_MAILDIR_ROOT=/var/mail/vhosts
|
||||
LANQIN_MAILDIR_SCAN_SECONDS=30
|
||||
TZ=Asia/Shanghai
|
||||
@@ -0,0 +1,35 @@
|
||||
# LanQin Email Docker 部署说明
|
||||
|
||||
## 启动
|
||||
|
||||
```bash
|
||||
cd deploy
|
||||
cp .env.example .env
|
||||
# 修改 LANQIN_PUBLIC_HOSTNAME / LANQIN_ADMIN_EMAIL / LANQIN_ADMIN_PASSWORD
|
||||
docker compose up -d --build
|
||||
```
|
||||
|
||||
## DNS
|
||||
|
||||
进入 Web 管理后台后,在“DNS 记录”面板查看每个域名需要配置的:
|
||||
|
||||
- MX
|
||||
- SPF TXT
|
||||
- DKIM TXT
|
||||
- DMARC TXT
|
||||
|
||||
配置完成后点击“检测”。
|
||||
|
||||
## 邮件服务边界
|
||||
|
||||
- Postfix 读取 `/data/lanqin.db` 中的 `domains`、`mailboxes`、`aliases`。
|
||||
- Dovecot 读取同一个 SQLite 数据库进行邮箱认证,并使用 `/var/mail/vhosts` 作为 Maildir 根目录。
|
||||
- OpenDKIM 启动时从 SQLite 导出域名 DKIM 私钥到容器内 `/etc/opendkim/keys`。
|
||||
- Go API 是 Webmail 和管理后台唯一入口;浏览器不直接连接 SMTP/IMAP。
|
||||
- Go API 会读取 `LANQIN_MAILDIR_ROOT=/var/mail/vhosts`,周期扫描 Maildir,把 Postfix/Dovecot 入站邮件同步成 Webmail 索引。
|
||||
|
||||
## 生产注意
|
||||
|
||||
- 替换 Dovecot 示例自签证书,建议在 Nginx 或边缘负载均衡终止 HTTPS。
|
||||
- 云厂商通常默认封禁 25 端口,需要单独申请解封。
|
||||
- SQLite 适合 V1 单机部署;多节点部署前迁移到 PostgreSQL,并把 Postfix/Dovecot maps 改为 PostgreSQL。
|
||||
@@ -0,0 +1,13 @@
|
||||
FROM golang:1.22-bookworm AS build
|
||||
WORKDIR /src/apps/api
|
||||
COPY apps/api/go.mod apps/api/go.sum ./
|
||||
RUN go mod download
|
||||
COPY apps/api ./
|
||||
RUN CGO_ENABLED=0 GOOS=linux go build -o /out/lanqin-api ./cmd/server
|
||||
|
||||
FROM debian:bookworm-slim
|
||||
RUN apt-get update && apt-get install -y --no-install-recommends ca-certificates tzdata && rm -rf /var/lib/apt/lists/*
|
||||
WORKDIR /app
|
||||
COPY --from=build /out/lanqin-api /usr/local/bin/lanqin-api
|
||||
EXPOSE 8080
|
||||
CMD ["lanqin-api"]
|
||||
@@ -0,0 +1,73 @@
|
||||
version: "3.9"
|
||||
|
||||
services:
|
||||
api:
|
||||
build:
|
||||
context: ..
|
||||
dockerfile: deploy/api.Dockerfile
|
||||
env_file: .env
|
||||
volumes:
|
||||
- lanqin-data:/data
|
||||
- maildata:/var/mail/vhosts:ro
|
||||
depends_on:
|
||||
- dovecot
|
||||
- postfix
|
||||
restart: unless-stopped
|
||||
|
||||
web:
|
||||
build:
|
||||
context: ..
|
||||
dockerfile: deploy/web.Dockerfile
|
||||
restart: unless-stopped
|
||||
|
||||
nginx:
|
||||
image: nginx:1.27-alpine
|
||||
volumes:
|
||||
- ./nginx/default.conf:/etc/nginx/conf.d/default.conf:ro
|
||||
ports:
|
||||
- "80:80"
|
||||
- "443:443"
|
||||
depends_on:
|
||||
- api
|
||||
- web
|
||||
restart: unless-stopped
|
||||
|
||||
postfix:
|
||||
build:
|
||||
context: ./postfix
|
||||
env_file: .env
|
||||
volumes:
|
||||
- lanqin-data:/data
|
||||
- maildata:/var/mail/vhosts
|
||||
ports:
|
||||
- "25:25"
|
||||
- "587:587"
|
||||
depends_on:
|
||||
- dovecot
|
||||
- opendkim
|
||||
restart: unless-stopped
|
||||
|
||||
dovecot:
|
||||
build:
|
||||
context: ./dovecot
|
||||
env_file: .env
|
||||
volumes:
|
||||
- lanqin-data:/data
|
||||
- maildata:/var/mail/vhosts
|
||||
ports:
|
||||
- "993:993"
|
||||
restart: unless-stopped
|
||||
|
||||
opendkim:
|
||||
build:
|
||||
context: ./opendkim
|
||||
env_file: .env
|
||||
volumes:
|
||||
- lanqin-data:/data:ro
|
||||
- dkim-keys:/etc/opendkim/keys
|
||||
restart: unless-stopped
|
||||
|
||||
volumes:
|
||||
lanqin-data:
|
||||
maildata:
|
||||
dkim-keys:
|
||||
@@ -0,0 +1,10 @@
|
||||
FROM debian:bookworm-slim
|
||||
ENV DEBIAN_FRONTEND=noninteractive
|
||||
RUN apt-get update && apt-get install -y --no-install-recommends dovecot-core dovecot-imapd dovecot-lmtpd dovecot-sqlite ssl-cert ca-certificates && rm -rf /var/lib/apt/lists/*
|
||||
COPY dovecot.conf /etc/dovecot/dovecot.conf
|
||||
COPY dovecot-sql.conf.ext /etc/dovecot/dovecot-sql.conf.ext
|
||||
COPY entrypoint.sh /entrypoint.sh
|
||||
RUN chmod +x /entrypoint.sh
|
||||
EXPOSE 993 24 12345
|
||||
CMD ["/entrypoint.sh"]
|
||||
|
||||
@@ -0,0 +1,5 @@
|
||||
driver = sqlite
|
||||
connect = /data/lanqin.db
|
||||
default_pass_scheme = BLF-CRYPT
|
||||
password_query = SELECT address AS user, password_hash AS password FROM mailboxes WHERE address = '%u' AND status = 'active'
|
||||
user_query = SELECT '/var/mail/vhosts/' || substr(address, instr(address, '@') + 1) || '/' || local_part AS home, 'maildir:/var/mail/vhosts/' || substr(address, instr(address, '@') + 1) || '/' || local_part || '/Maildir' AS mail, 5000 AS uid, 5000 AS gid FROM mailboxes WHERE address = '%u' AND status = 'active'
|
||||
@@ -0,0 +1,48 @@
|
||||
protocols = imap lmtp
|
||||
listen = *
|
||||
base_dir = /var/run/dovecot/
|
||||
|
||||
log_path = /dev/stderr
|
||||
info_log_path = /dev/stdout
|
||||
|
||||
ssl = yes
|
||||
ssl_cert = </etc/ssl/certs/ssl-cert-snakeoil.pem
|
||||
ssl_key = </etc/ssl/private/ssl-cert-snakeoil.key
|
||||
|
||||
mail_home = /var/mail/vhosts/%d/%n
|
||||
namespace inbox {
|
||||
inbox = yes
|
||||
mailbox Drafts { special_use = \Drafts }
|
||||
mailbox Sent { special_use = \Sent }
|
||||
mailbox Trash { special_use = \Trash }
|
||||
mailbox Archive { special_use = \Archive }
|
||||
mailbox Spam { special_use = \Junk }
|
||||
}
|
||||
|
||||
passdb {
|
||||
driver = sql
|
||||
args = /etc/dovecot/dovecot-sql.conf.ext
|
||||
}
|
||||
userdb {
|
||||
driver = sql
|
||||
args = /etc/dovecot/dovecot-sql.conf.ext
|
||||
}
|
||||
|
||||
service imap-login {
|
||||
inet_listener imaps { port = 993 ssl = yes }
|
||||
}
|
||||
|
||||
service lmtp {
|
||||
inet_listener lmtp { address = 0.0.0.0 port = 24 }
|
||||
}
|
||||
|
||||
service auth {
|
||||
inet_listener postfix-auth {
|
||||
address = 0.0.0.0
|
||||
port = 12345
|
||||
}
|
||||
}
|
||||
|
||||
protocol lmtp {
|
||||
postmaster_address = postmaster@localhost
|
||||
}
|
||||
@@ -0,0 +1,7 @@
|
||||
#!/bin/sh
|
||||
set -eu
|
||||
addgroup --system --gid 5000 vmail 2>/dev/null || true
|
||||
adduser --system --uid 5000 --gid 5000 --home /var/mail/vhosts --no-create-home vmail 2>/dev/null || true
|
||||
mkdir -p /var/mail/vhosts
|
||||
chown -R 5000:5000 /var/mail/vhosts
|
||||
exec dovecot -F
|
||||
@@ -0,0 +1,22 @@
|
||||
server {
|
||||
listen 80;
|
||||
server_name _;
|
||||
|
||||
location /api/ {
|
||||
proxy_pass http://api:8080/api/;
|
||||
proxy_http_version 1.1;
|
||||
proxy_set_header Host $host;
|
||||
proxy_set_header X-Real-IP $remote_addr;
|
||||
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
|
||||
proxy_set_header X-Forwarded-Proto $scheme;
|
||||
}
|
||||
|
||||
location /healthz {
|
||||
proxy_pass http://api:8080/healthz;
|
||||
}
|
||||
|
||||
location / {
|
||||
proxy_pass http://web:80;
|
||||
proxy_set_header Host $host;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,7 @@
|
||||
server {
|
||||
listen 80;
|
||||
server_name _;
|
||||
root /usr/share/nginx/html;
|
||||
index index.html;
|
||||
location / { try_files $uri $uri/ /index.html; }
|
||||
}
|
||||
@@ -0,0 +1,9 @@
|
||||
FROM debian:bookworm-slim
|
||||
ENV DEBIAN_FRONTEND=noninteractive
|
||||
RUN apt-get update && apt-get install -y --no-install-recommends opendkim opendkim-tools sqlite3 ca-certificates && rm -rf /var/lib/apt/lists/*
|
||||
COPY opendkim.conf /etc/opendkim.conf
|
||||
COPY TrustedHosts /etc/opendkim/TrustedHosts
|
||||
COPY entrypoint.sh /entrypoint.sh
|
||||
RUN chmod +x /entrypoint.sh
|
||||
EXPOSE 8891
|
||||
CMD ["/entrypoint.sh"]
|
||||
@@ -0,0 +1,5 @@
|
||||
127.0.0.1
|
||||
localhost
|
||||
10.0.0.0/8
|
||||
172.16.0.0/12
|
||||
192.168.0.0/16
|
||||
@@ -0,0 +1,19 @@
|
||||
#!/bin/sh
|
||||
set -eu
|
||||
mkdir -p /etc/opendkim/keys
|
||||
: > /etc/opendkim/KeyTable
|
||||
: > /etc/opendkim/SigningTable
|
||||
if [ -f /data/lanqin.db ]; then
|
||||
sqlite3 -separator '|' /data/lanqin.db "SELECT name, dkim_selector, dkim_private_key FROM domains WHERE status='active';" | while IFS='|' read -r domain selector private_key; do
|
||||
[ -n "$domain" ] || continue
|
||||
dir="/etc/opendkim/keys/$domain"
|
||||
mkdir -p "$dir"
|
||||
keyfile="$dir/$selector.private"
|
||||
printf '%s' "$private_key" | base64 -d > "$keyfile"
|
||||
chmod 600 "$keyfile"
|
||||
echo "$selector._domainkey.$domain $domain:$selector:$keyfile" >> /etc/opendkim/KeyTable
|
||||
echo "*@${domain} ${selector}._domainkey.${domain}" >> /etc/opendkim/SigningTable
|
||||
done
|
||||
fi
|
||||
chown -R opendkim:opendkim /etc/opendkim
|
||||
exec opendkim -f -x /etc/opendkim.conf
|
||||
@@ -0,0 +1,12 @@
|
||||
Syslog yes
|
||||
UMask 002
|
||||
Mode sv
|
||||
Canonicalization relaxed/simple
|
||||
SubDomains no
|
||||
OversignHeaders From
|
||||
Socket inet:8891@0.0.0.0
|
||||
UserID opendkim:opendkim
|
||||
KeyTable /etc/opendkim/KeyTable
|
||||
SigningTable refile:/etc/opendkim/SigningTable
|
||||
ExternalIgnoreList /etc/opendkim/TrustedHosts
|
||||
InternalHosts /etc/opendkim/TrustedHosts
|
||||
@@ -0,0 +1,10 @@
|
||||
FROM debian:bookworm-slim
|
||||
ENV DEBIAN_FRONTEND=noninteractive
|
||||
RUN apt-get update && apt-get install -y --no-install-recommends postfix postfix-sqlite ca-certificates rsyslog && rm -rf /var/lib/apt/lists/*
|
||||
COPY main.cf /etc/postfix/main.cf
|
||||
COPY master.cf /etc/postfix/master.cf
|
||||
COPY sqlite-*.cf /etc/postfix/
|
||||
COPY entrypoint.sh /entrypoint.sh
|
||||
RUN chmod +x /entrypoint.sh
|
||||
EXPOSE 25 587
|
||||
CMD ["/entrypoint.sh"]
|
||||
@@ -0,0 +1,9 @@
|
||||
#!/bin/sh
|
||||
set -eu
|
||||
: "${LANQIN_PUBLIC_HOSTNAME:=mail.example.com}"
|
||||
postconf -e "myhostname = ${LANQIN_PUBLIC_HOSTNAME}"
|
||||
postconf -e "myorigin = ${LANQIN_PUBLIC_HOSTNAME}"
|
||||
postconf -e "smtpd_milters = inet:opendkim:8891"
|
||||
postconf -e "non_smtpd_milters = inet:opendkim:8891"
|
||||
postfix check
|
||||
exec postfix start-fg
|
||||
@@ -0,0 +1,30 @@
|
||||
compatibility_level = 3.6
|
||||
myhostname = mail.example.com
|
||||
myorigin = $myhostname
|
||||
mydestination = localhost
|
||||
inet_interfaces = all
|
||||
inet_protocols = all
|
||||
|
||||
# SQLite maps read the same LanQin DB created by the Go API.
|
||||
virtual_mailbox_domains = sqlite:/etc/postfix/sqlite-domains.cf
|
||||
virtual_mailbox_maps = sqlite:/etc/postfix/sqlite-mailboxes.cf
|
||||
virtual_alias_maps = sqlite:/etc/postfix/sqlite-aliases.cf
|
||||
virtual_transport = lmtp:inet:dovecot:24
|
||||
virtual_mailbox_base = /var/mail/vhosts
|
||||
|
||||
smtpd_banner = $myhostname ESMTP LanQin Email
|
||||
smtpd_relay_restrictions = permit_mynetworks, permit_sasl_authenticated, reject_unauth_destination
|
||||
smtpd_recipient_restrictions = permit_mynetworks, permit_sasl_authenticated, reject_unauth_destination
|
||||
|
||||
# Submission auth via Dovecot.
|
||||
smtpd_sasl_type = dovecot
|
||||
smtpd_sasl_path = inet:dovecot:12345
|
||||
smtpd_sasl_auth_enable = yes
|
||||
smtpd_tls_security_level = may
|
||||
smtp_tls_security_level = may
|
||||
|
||||
# DKIM milter.
|
||||
milter_protocol = 6
|
||||
milter_default_action = accept
|
||||
smtpd_milters = inet:opendkim:8891
|
||||
non_smtpd_milters = inet:opendkim:8891
|
||||
@@ -0,0 +1,29 @@
|
||||
smtp inet n - y - - smtpd
|
||||
submission inet n - y - - smtpd
|
||||
-o syslog_name=postfix/submission
|
||||
-o smtpd_tls_security_level=may
|
||||
-o smtpd_sasl_auth_enable=yes
|
||||
-o smtpd_relay_restrictions=permit_sasl_authenticated,reject
|
||||
pickup unix n - y 60 1 pickup
|
||||
cleanup unix n - y - 0 cleanup
|
||||
qmgr unix n - n 300 1 qmgr
|
||||
tlsmgr unix - - y 1000? 1 tlsmgr
|
||||
rewrite unix - - y - - trivial-rewrite
|
||||
bounce unix - - y - 0 bounce
|
||||
defer unix - - y - 0 bounce
|
||||
trace unix - - y - 0 bounce
|
||||
verify unix - - y - 1 verify
|
||||
flush unix n - y 1000? 0 flush
|
||||
proxymap unix - - n - - proxymap
|
||||
proxywrite unix - - n - 1 proxymap
|
||||
smtp unix - - y - - smtp
|
||||
relay unix - - y - - smtp
|
||||
showq unix n - y - - showq
|
||||
error unix - - y - - error
|
||||
retry unix - - y - - error
|
||||
discard unix - - y - - discard
|
||||
local unix - n n - - local
|
||||
virtual unix - n n - - virtual
|
||||
lmtp unix - - y - - lmtp
|
||||
anvil unix - - y - 1 anvil
|
||||
scache unix - - y - 1 scache
|
||||
@@ -0,0 +1,2 @@
|
||||
dbpath = /data/lanqin.db
|
||||
query = SELECT destination FROM aliases WHERE source='%s' AND enabled=1 UNION SELECT address FROM mailboxes WHERE address='%s' AND status='active'
|
||||
@@ -0,0 +1,2 @@
|
||||
dbpath = /data/lanqin.db
|
||||
query = SELECT 1 FROM domains WHERE name='%s' AND status='active'
|
||||
@@ -0,0 +1,2 @@
|
||||
dbpath = /data/lanqin.db
|
||||
query = SELECT 'vhosts/' || substr(address, instr(address, '@') + 1) || '/' || local_part || '/Maildir/' FROM mailboxes WHERE address='%s' AND status='active'
|
||||
@@ -0,0 +1,11 @@
|
||||
FROM node:20-bookworm-slim AS build
|
||||
WORKDIR /src/apps/web
|
||||
COPY apps/web/package.json apps/web/package-lock.json* ./
|
||||
RUN npm ci || npm install
|
||||
COPY apps/web ./
|
||||
RUN npm run build
|
||||
|
||||
FROM nginx:1.27-alpine
|
||||
COPY --from=build /src/apps/web/dist /usr/share/nginx/html
|
||||
COPY deploy/nginx/web.conf /etc/nginx/conf.d/default.conf
|
||||
EXPOSE 80
|
||||
Reference in New Issue
Block a user