Proxmox VE(PVE)預設透過本地 Postfix 寄送通知郵件,但若直接發送,常會因為 DNS 設定不完整、寄件人身份不符等原因被拒收。這篇教學將說明如何讓 PVE 經由自有 SMTP 伺服器(使用 SSL)發送通知,並映射寄件人為合法帳號。
🧾 前提環境(已脫敏)
| 項目 | 範例(脫敏) |
|---|---|
| PVE 主機 IP | 192.168.X.X |
| PVE 主機名 | pve.internal.domain |
| SMTP 伺服器 | smtp.external-mail.net |
| SMTP 埠口 | NNNN(SSL 連線) |
| 發件信箱(登入帳號) | notify@external-mail.net |
| 密碼 | <your-smtp-password> |
1️⃣ 安裝必要套件
apt update
apt install -y libsasl2-modules mailutils
libsasl2-modules:讓 Postfix 支援 SMTP 認證mailutils:提供
2️⃣ 設定 /etc/postfix/main.cf
使用編輯器打開:
nano /etc/postfix/main.cf
加入或修改以下內容:
myhostname = mail.external-mail.net
relayhost = [smtp.external-mail.net]:NNNN
smtp_use_tls = yes
smtp_tls_wrappermode = yes
smtp_tls_security_level = encrypt
smtp_sasl_auth_enable = yes
smtp_sasl_password_maps = hash:/etc/postfix/sasl_passwd
smtp_sasl_security_options = noanonymous
smtp_sasl_tls_security_options = noanonymous
smtp_generic_maps = hash:/etc/postfix/generic
smtputf8_enable = no
inet_interfaces = loopback-only
mynetworks = 127.0.0.0/8
recipient_delimiter = +
compatibility_level = 2
3️⃣ 設定登入憑證檔 /etc/postfix/sasl_passwd
cat <<EOF > /etc/postfix/sasl_passwd
[smtp.external-mail.net]:NNNN notify@external-mail.net:<your-smtp-password>
EOF
chmod 600 /etc/postfix/sasl_passwd
postmap /etc/postfix/sasl_passwd
4️⃣ 設定寄件人映射 /etc/postfix/generic
cat <<EOF > /etc/postfix/generic
root notify@external-mail.net
@pve.internal.domain notify@external-mail.net
EOF
postmap /etc/postfix/generic
將所有從
root或本地主機發出的信件寄件人都轉為合法 SMTP 帳號。
5️⃣ 重啟 Postfix
systemctl restart postfix
6️⃣ 測試發信
echo "This is a test email from PVE." | mail -s "SMTP Test" your@email
日誌確認:
tail -n 30 /var/log/mail.log
應該看到 status=sent 字樣,且寄件人為 notify@external-mail.net。
📌 常見錯誤與解決
| 錯誤訊息 | 解釋 | 解法 |
|---|---|---|
SASL authentication failed | 認證失敗 | 確認帳號密碼正確,安裝 libsasl2-modules |
no worthy mechs found | 缺少認證機制模組 | 安裝 libsasl2-modules |
Sender address rejected | 寄件人與登入帳號不符 | 設定 smtp_generic_maps 映射 |
SMTPUTF8 is required... | SMTP 不支援 UTF8 擴展 | 加入 smtputf8_enable = no |
.db 檔案不存在 | 忘記轉換表格 | 執行 postmap 建立 .db 檔案 |
📦 備份 SMTP 設定(建議)
tar czvf pve-smtp-config.tar.gz \
/etc/postfix/main.cf \
/etc/postfix/sasl_passwd* \
/etc/postfix/generic*
✅ 結語
完成設定後,你的 PVE 系統將能夠:
- 透過 SSL 與外部 SMTP 安全發信
- 使用合法帳號作為寄件人,通過驗證
- 成功寄出通知,如備份、錯誤警告等
- 不需修改主機名與 hosts,配置更簡潔