#pSmtpQueue
建议:在 nextxch 前部署 Proxmox Mail Gateway 作为附加防护层
前置邮件网关接收来自互联网的所有邮件,使用第二套独立的反垃圾邮件和防病毒引擎进行检查,只将干净的邮件转发给 nextxch。本页介绍架构、在 nextxch 前部署 Proxmox Mail Gateway(开源,AGPLv3)的分步设置,以及相关的 nextxch 设置。
网关是可选的:nextxch 自带垃圾邮件和病毒防护。如果使用网关,重要的是:在 nextxch 中将网关 IP 添加为受信任网关(第 5 步)。这样 nextxch 会从网关的 Received 头中读取真实发件人 IP,并继续正确评估 SPF、DMARC、灰名单和 DNSBL,而不是检查网关 IP。
为什么在前端部署网关可能有意义
- 纵深防御:必须有两套独立系统同时失守,恶意邮件才会进入邮箱。单个产品的弱点本身不足以造成危害。
- 第二套反垃圾邮件和防病毒引擎:Proxmox Mail Gateway 使用自己的规则、贝叶斯过滤器、SPF、DNSBL 和 ClamAV。一个过滤器漏掉的,另一个往往能拦住。
- 隔离区:可疑邮件会被扣留在网关中,管理员或用户可通过垃圾邮件报告查看并放行。
- 与互联网解耦:只有网关在端口 25 上接受来自互联网的连接。nextxch 位于其后,端口 25 仅对网关开放。
- 维护期间缓冲:如果 nextxch 因更新或维护短暂不可用,网关会将入站邮件保留在其队列中,并在之后投递。
客观评估:nextxch 自带垃圾邮件防护(带自适应过滤器的 SpamGuard、SPF/DKIM/DMARC/ARC、灰名单、DNSBL、钓鱼启发式检测)并集成 ClamAV。对大多数部署而言这已足够。前置网关是可选的,在要求更高时才值得部署:策略要求多级过滤、集中式隔离区、一个 MX 之后有多台邮件服务器,或严格的网络隔离。
架构:互联网 -> Proxmox Mail Gateway -> nextxch
MX 记录指向网关。网关在端口 25 上接收邮件,进行过滤后通过 SMTP 转发给 nextxch。nextxch 也可选择通过网关的内部端口 26 发送出站邮件。
Proxmox® 是 Proxmox Server Solutions GmbH 的注册商标。此名称仅用于描述;nextxch 与 Proxmox Server Solutions GmbH 无关联,也未获得其认可或认证。
设置概览
按此顺序可避免丢失邮件:先完整设置并测试网关,然后切换 MX 记录,最后关闭 nextxch 上的端口 25。
1. Install Proxmox Mail Gateway (ISO, on Debian or as an LXC container)
2. Add relay domains (every domain nextxch accepts)
3. Default relay = nextxch host, port 25 (Mail Proxy -> Relaying)
4. Enable receiver verification, TLS and a certificate in the gateway
5. nextxch: add the gateway IP as a trusted gateway (SpamGuard)
6. Send a test message through the gateway, check Message Trace in nextxch
7. Switch the MX record to the gateway (remove the old MX only after the TTL expires)
8. Firewall: allow port 25 on nextxch from the gateway only
9. Optional outbound: gateway as smart host in nextxch (port 26, STARTTLS)
Example values on this page:
Gateway: pmg.company.com 203.0.113.25 (public, MX)
nextxch: mail.company.com 10.0.0.20 (internal, mailboxes)
1. 安装 Proxmox Mail Gateway
Proxmox Mail Gateway 可作为独立设备运行(在硬件上或作为虚拟机通过 ISO 安装程序安装),也可作为软件包安装在现有 Debian 系统上,或作为 LXC 容器运行。如果您使用 Proxmox VE,可在设备管理器中找到现成的容器模板。之后通过端口 8006 上的 Web 界面进行管理。
Option A: ISO installer (hardware or VM)
Download the ISO from proxmox.com/downloads -> boot -> run the installer
Host name: pmg.company.com (FQDN, matching the future MX and PTR)
IP: static IP, e.g. 203.0.113.25 or a DMZ address behind NAT
Option B: on an existing Debian system
Add the Proxmox package repository and install the packages as described in
"Install Proxmox Mail Gateway on Debian" in the PMG admin guide
Option C: LXC container in Proxmox VE
Proxmox VE -> Storage -> CT Templates -> Templates -> section "mail"
-> download the Proxmox Mail Gateway template -> create the container
Web interface: https://pmg.company.com:8006 (port 8006 from the admin network only)
Repositories: without a subscription, add the "pmg-no-subscription" repository.
For production, Proxmox recommends the enterprise repository (with subscription).
2. 在网关中配置中继域、默认中继和收件人验证
所有设置均位于 PMG Web 界面的 Configuration -> Mail Proxy 下。网关只接收所列中继域的邮件,过滤后转交给默认中继。
Configuration -> Mail Proxy -> Relay Domains
company.com
company-group.com (every domain configured in nextxch, including alias domains)
Configuration -> Mail Proxy -> Relaying
Default Relay: mail.company.com (or 10.0.0.20)
Relay Port: 25
Relay Protocol: SMTP
Disable MX lookup: yes (address the nextxch host directly)
Configuration -> Mail Proxy -> Ports
External SMTP Port: 25 (from the internet, untrusted)
Internal SMTP Port: 26 (from nextxch, trusted, for outbound mail)
Configuration -> Mail Proxy -> Options
Verify Receivers: 550 (reject unknown recipients right away)
SPF: yes
DNSBL Sites: e.g. zen.spamhaus.org (observe the list's terms of use)
Several internal servers: Configuration -> Mail Proxy -> Transports
(domain or single address -> its own target server)
3. 将 MX 记录切换到网关
仅在一封测试邮件经网关到达 nextxch 后(/admin/ 中的 Message Trace)再进行切换。事先将 MX 记录的 TTL 降低到几分钟。不要更改 nextxch 自身的记录(A/AAAA、PTR、Autodiscover):客户端仍直接连接 nextxch。
; Gateway
pmg.company.com. 3600 IN A 203.0.113.25
; PTR for 203.0.113.25 at your provider: pmg.company.com
; MX points to the gateway only
company.com. 3600 IN MX 10 pmg.company.com.
; nextxch stays reachable for clients (IMAP, SMTP submission, webmail)
mail.company.com. 3600 IN A 198.51.100.20
Test beforehand, without a DNS change:
swaks --to anna.weber@company.com --server pmg.company.com --port 25 --tls
4. 可选出站:在 nextxch 中将网关设为智能主机
此后出站邮件也会经过网关的过滤器(例如病毒扫描、统计)。在管理控制台的“SMTP、队列控制与 Live MX Tester”(#pSmtpQueue)下,将网关设为全局智能主机,或使用 SMTP 路由只让特定发件人经由网关发送。重要:此时网关的公网 IP 必须包含在您各个域的 SPF 记录中,且其 PTR 必须与网关的 HELO 名称一致。
# A) Global smart host: all outbound mail through the gateway
nextxch-cli update SmtpQueue --set outboundSmartHost=pmg.company.com \
--set outboundSmartPort=26 --set outboundSmartHostTlsMode=StartTlsRequired
# B) Exception: one partner domain still directly via DNS MX (route without target host)
nextxch-cli create Route --set domain=partner.com --set bypassSmartHost=true \
--set description="direct via MX, not through the gateway"
# C) Only certain senders through the gateway (#pSmtpQueue -> domain routes)
# Destination domain: *
# Only for senders: company.com, *.company.com (SenderDomains)
# Target host: pmg.company.com:26 (several, comma-separated = failover)
# TLS mode: StartTlsRequired
# Priority: 50 (smaller = first; default 100)
# Add the gateway IP to the SPF record of the sender domain:
company.com. IN TXT "v=spf1 mx ip4:203.0.113.25 -all"
# In the gateway: add the nextxch IP under Configuration -> Mail Proxy -> Networks
# if nextxch is not in the same subnet as the gateway.
5. 在 nextxch 中将网关 IP 添加为受信任
邮件网关会自行接收邮件并再次投递。因此对 nextxch 而言,投递方 IP 始终是网关 IP。为了让 SPF、DMARC、灰名单、DNSBL 和反向 DNS 检查仍然判断真实发件人,请在 SpamGuard & ClamAV (#pSpam) 的"受信任网关"中添加该网关。对于来自这些 IP 的连接,nextxch 会从网关写入的 Received 头中读取发件人 IP。仅对来自所列 IP 的连接才会评估邮件头,因此直接投递的发件人无法借此伪造其 IP。TrustedProxyCidrs (Cluster:EnableProxyProtocol) 则是另一回事:它们仅适用于使用 PROXY 协议的 TCP 代理,例如 HAProxy。
# nextxch: add the gateway as trusted (public and internal IP, CIDR allowed)
# (admin cockpit: SpamGuard & ClamAV (#pSpam) -> "Trusted gateways")
nextxch-cli update SpamGuard --set trustedRelayCidrs=203.0.113.25,10.0.0.25
# Check: send a test message through the gateway, then in the spam analyzer or Message Trace
# TRUSTED_RELAY Via gateway 10.0.0.25, sender IP 198.51.100.7 from Received header
# SPF_PASS (SPF now checked against 198.51.100.7)
# Stays active in nextxch:
# SPF/DKIM/DMARC/ARC, greylisting, DNSBL, adaptive content filter,
# phishing heuristics, allow/block lists, ClamAV (if enabled)
# Connection limit: all inbound mail comes from one IP.
# Check MaxConnectionsPerIp (#pSmtpQueue, default 48) for high volumes.
6. 两段链路上的防火墙与 TLS
在主机或边界防火墙(Windows 防火墙、nftables、pfSense/OPNsense)中关闭 nextxch 的端口 25。nextxch IP 规则不适合用于此目的,因为它们同时作用于所有 SMTP 端口,因此也会影响客户端使用的 465 和 587。请对两段链路都进行加密:互联网 <-> 网关,以及网关 <-> nextxch。
Firewall nextxch (inbound)
TCP 25 only from 203.0.113.25 / 10.0.0.25 (gateway)
TCP 465, 587 clients (SMTP submission) -> stay open
TCP 993, 443 clients (IMAP, webmail, DAV, push) -> stay open
Firewall gateway (inbound)
TCP 25 from the internet
TCP 26 from nextxch only (smart host, if used)
TCP 8006 from the admin network only
TLS internet <-> gateway
Configuration -> Mail Proxy -> TLS: "Enable TLS" on
Certificate: Certificates -> ACME (Let's Encrypt) for pmg.company.com
TLS gateway -> nextxch
nextxch offers STARTTLS on port 25 with the certificate of mail.company.com
Gateway: TLS destination policy for mail.company.com = encrypt
(or verify if the default relay is entered as a host name)
TLS nextxch -> gateway (smart host)
outboundSmartHostTlsMode = StartTlsRequired
7. DKIM/DMARC、灰名单与反向散射
实践中经常被忽视的三点:网关不得修改出站邮件,灰名单只应在一处运行,未知收件人必须在 SMTP 会话期间被拒绝。
DKIM / DMARC
- nextxch signs outbound mail with DKIM. The gateway forwards it unchanged.
- No disclaimer rule for outbound mail and no content changes in the gateway
(otherwise the DKIM signature breaks and DMARC fails at the recipient).
- Leave DKIM signing off in the gateway; maintain disclaimers in nextxch if needed.
Greylisting
- Slows down spam bots but delays first messages from new senders (usually < 30 minutes per PMG docs).
- Run it in the gateway only; behind the gateway it would be ineffective in nextxch.
- For time-critical senders (e.g. login codes, order confirmations) use the welcomelist,
or skip greylisting entirely if the other filters are sufficient.
Avoid backscatter
- Verify Receivers = 550: the gateway asks nextxch via RCPT TO whether the address exists.
- nextxch rejects unknown recipients at RCPT TO, so the check takes effect immediately.
- Catch-all addresses in nextxch defeat the check and should be avoided.
8. 许可证与费用(截至 2026 年 11 月 1 日)
Proxmox Mail Gateway 以 GNU AGPLv3 开源,无需订阅即可完整使用;此时更新来自 pmg-no-subscription 存储库,Proxmox 将其定位于测试和非生产系统。订阅按主机和年计费,据 Proxmox 介绍包含不限数量的用户和域,并可访问企业存储库。以下价格来自 Proxmox 价格页面,可能会变动,一切以 proxmox.com 为准。nextxch 不销售 Proxmox 订阅。
Licence: GNU Affero General Public License v3 (AGPLv3), since PMG 5.0
Optional subscriptions per host and year (net, per proxmox.com, as of 1 Nov 2026):
Community EUR 190 no ticket support (forum)
Basic EUR 540 5 tickets/year, response 1 business day
Standard EUR 1,260 15 tickets/year, response 4 hours
Premium EUR 1,900 unlimited tickets, response 2 hours
(response = first reply to critical requests within business hours)
Sources:
https://www.proxmox.com/en/products/proxmox-mail-gateway/pricing
https://pmg.proxmox.com/pmg-docs/pmg-admin-guide.html (admin guide 9.1.1: licence, repositories, ports)
设置、默认值与最佳实践
| 设置 / 位置 | 说明 | 默认值 | 生产环境最佳实践 |
|---|---|---|---|
PMG: Relay Domains (Mail Proxy) |
网关接收并转发邮件的域列表。发往其他域的邮件将被拒绝。 | leer |
添加在 nextxch 中配置的每个域,包括别名域。在 nextxch 中添加域时,也要将其添加到网关。 |
PMG: Default Relay + Port (Mail Proxy -> Relaying) |
过滤后入站邮件的目标(Postfix transport)。可通过 Transports 为每个域添加其他内部服务器。 | Port 25 · SMTP |
mail.company.com 或 10.0.0.20,端口 25,协议 SMTP。如果您输入的主机名本身有 MX 记录,请启用"Disable MX lookup"。 |
PMG: Verify Receivers (Mail Proxy -> Options) |
收件人验证:网关在接收前通过 RCPT TO 向 nextxch 询问地址是否存在,并在 SMTP 会话期间拒绝未知收件人。 | aus |
设置为 550。可防止反向散射,因为网关绝不会接受发往虚构地址、日后不得不退回的邮件。 |
PMG: TLS + Zertifikat |
网关的入站和出站连接使用 STARTTLS。若没有自己的证书,PMG 会生成自签名证书。 | TLS aus |
开启 TLS,通过 ACME(Let's Encrypt)为 pmg.company.com 获取受信任的证书,并为 nextxch 主机设置 "encrypt" TLS 策略。 |
PMG: Disclaimer & DKIM-Signatur |
Disclaimer 规则动作会在正文末尾追加文本;DKIM Signing 会对内部端口上收到的邮件进行签名。 | aus |
两项都保持关闭。nextxch 使用 DKIM 签名;网关对内容的任何修改都会破坏签名,进而导致 DMARC 失败。免责声明只在 nextxch 中维护(在签名前添加)。 |
nextxch: Smart-Host (#pSmtpQueue · outboundSmartHost) |
全局智能主机:所有出站邮件都发送到此中继,而不是直接发往收件人的 MX。 | leer (direkt per MX) · Port 25 |
pmg.company.com,中继端口 26(网关的内部端口),TLS 模式 StartTlsRequired,不使用 SMTP AUTH。在网关中,必须将 nextxch IP 列入 Networks(同一子网自动允许)。 |
nextxch: Route · SenderDomains |
SMTP 路由的发件人条件:域(company.com、*.company.com)或地址(billing@company.com、*@company.com)。留空 = 所有发件人。 | leer |
只让特定租户经由网关发送:创建一条目标域为 *、SenderDomains = company.com、目标主机为 pmg.company.com:26 的路由。 |
nextxch: Route · Priority |
同一级别路由之间的顺序;数字较小者优先,其次是更具体的模式。 | 100 |
排名先于优先级:发件人 + 目标域,其次是目标域,再次是仅发件人(目标为 *),然后是 *,然后是全局智能主机,最后是 DNS MX。 |
nextxch: Route · BypassSmartHost |
仅适用于没有目标主机的路由:即使设置了全局智能主机,发往此域的邮件也直接通过 DNS MX 投递。 | false |
适用于不应经过网关的个别合作伙伴域。如果路由已设置目标主机,则忽略此开关。 |
nextxch: Vertrauenswürdige Gateways (#pSpam · trustedRelayCidrs) |
上游网关的 IP 或 CIDR 网段。当连接来自这些地址时,nextxch 从最上方一个不是由所列网关或 localhost 写入的 Received 头中获取发件人 IP 和 HELO。 | leer |
添加公网和内网网关 IP,例如 203.0.113.25 和 10.0.0.25。仅限您自己的网关:来自所列 IP 的 Received 头将被视为可信。垃圾邮件分析器随后会显示规则 TRUSTED_RELAY 及检测到的发件人 IP。 |
nextxch: SPF, DKIM, DMARC & ARC, Greylisting, DNSBL (#pSpam) |
将网关列入后,它们会检查真实的发件人 IP。否则它们只能看到网关 IP,对于其他域,SPF 大多会返回 softfail 或 fail。 | abhängig von der Konfiguration |
保持开启。在网关和 nextxch 中同时检查并无害处;如果只想在一处使用灰名单,请在网关中保留,在 nextxch 中关闭。 |
Firewall: Port 25 auf nextxch |
切换 MX 后,只有网关可以通过端口 25 访问 nextxch。 | offen für alle |
在主机或边界防火墙中,仅允许来自 203.0.113.25 或内部网关 IP 的端口 25 访问。端口 465、587、993 和 443 对客户端保持开放。 |