#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、網路釣魚啟發式)並並行協調多達 8 個防毒引擎(Windows AMSI、YARA/Sanesecurity、Cymru MHR、MalwareBazaar、VirusTotal Hash、ClamAV、RFC 3507 ICAP、Rspamd/CLI)。對大多數安裝而言這樣就夠了。前端閘道是選用的,對於更高需求才能發揮效益:需要多階段過濾、中央隔離區、單一 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 上的網頁介面進行管理。
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 網頁介面的 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 對用戶端保持開放。 |