# PVE SMTP Email 設置


# Postfix 設定


# 安裝 libsasl2-modules

1
2
apt install libsasl2-modules -y
# 協助 SMTP SASL 驗證

# SMTP 設定

修改 main.cf

1
nano /etc/postfix/main.cf
  1. 將 mydestination 這行註解
  2. 將 relayhost 也註解
  3. 添加 SMTP Server 的設定
    • relayhost = YOUR HOST NAME
    • smtp_use_tls = no # 不使用 TLS
    • smtp_sasl_auth_enable = yes # 啟用 sasl 驗證
    • smtp_sasl_security_options = # 不使用安全選項
    • smtp_sasl_password_maps = hash:/etc/postfix/sasl_passwd # SASL 帳號密碼位置
    • smtp_tls_CAfile = /etc/ssl/certs/Entrust_Root_Certification_Authority.pem # 憑證位置
    • maillog_file = /var/log/mail.log # 加入他才會生成 log 檔案
    • syslog_name = postfix # postfix log 前墜

# 完成樣貌

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
# See /usr/share/postfix/main.cf.dist for a commented, more complete version

myhostname=pve.itri.org.tw

smtpd_banner = $myhostname ESMTP $mail_name (Debian/GNU)
biff = no

# appending .domain is the MUA's job.
append_dot_mydomain = no

# Uncomment the next line to generate "delayed mail" warnings
#delay_warning_time = 4h

alias_maps = hash:/etc/aliases
alias_database = hash:/etc/aliases
#mydestination = $myhostname, localhost.$mydomain, localhost
#relayhost =
mynetworks = 127.0.0.0/8
inet_interfaces = loopback-only
recipient_delimiter = +

compatibility_level = 2

relayhost = YOUR SMTP Server DOMAIN # SMTP Server
smtp_use_tls = no # 不使用 TLS
smtp_sasl_auth_enable = yes # 開啟 SASL 驗證
smtp_sasl_security_options = noanonymous
smtp_sasl_password_maps = hash:/etc/postfix/sasl_passwd # 放置 SMTP 帳號密碼位置
smtp_tls_CAfile = /etc/ssl/certs/Entrust_Root_Certification_Authority.pem

maillog_file = /var/log/mail.log # 加入他才會生成 log 檔案
syslog_name = postfix #系統 log 名稱

# SASL 帳戶設定

新增 sasl_passwd 去新增帳戶

1
nano /etc/postfix/sasl_passwd

添加內容
格式: Server Email:Password

1
2
SMTP_DOMAIN SMTP_ACCOUNT:SMTP_PASSWORD
#Host # Login Account:Password

# 添加帳密到 map 上

1
2
3
postmap hash:/etc/postfix/sasl_passwd #添加帳密到 map
chmod 600 /etc/postfix/sasl_passwd # 限制 root 可以存取
systemctl restart postfix # 刷新 postfix

# 執行寄信

-s 是收件者
- r 是寄件者

1
echo "Test email from Proxmox: $(hostname)" | mail -s "Proxmox Testing 25" RECEIVER_MAIL -r SMTP_EMAIL

# 參考資料

  • Proxmox Email Notification Configuration
更新於