Skip to main content

2. 增加 Email 通知

前往 PVE 後台
左側 pve ➝ 命令列

epower-pve210.png

安裝必要的套件服務

輸入 apt install libsasl2-modules postfix-pcre
安裝完後輸入 vim /etc/postfix/main.cf 編輯這個檔案

# See /usr/share/postfix/main.cf.dist for a commented, more complete version

myhostname=tn2-pve-03.local

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 = +

新增以下的內容

smtp_use_tls = yes
smtp_sasl_auth_enable = yes
smtp_sasl_password_maps = hash:/etc/postfix/sasl_passwd
smtp_tls_CAfile = /etc/ssl/certs/ca-certificates.crt

#mydestination = $myhostname, localhost.$mydomain, localhost

新增檔案

編輯完後輸入 vim /etc/postfix/sasl_passwd
在輸入 gmail 的帳號及密碼

smtp.gmail.com:587 是郵件伺服器及端口
test@test.com 是 Gmail 帳號 (要輸入自己的)
Gmail 帳號的冒號後面是密碼

範例 : smtp.gmail.com:587 test@test.com:cjidjsiofkf

※如果你的 Gmail 帳號有開啟二步驟驗證 冒號 後的密碼必須輸入 Google 的應用程式密碼※

Google 應用程式密碼

前往 Google 帳戶頁面
左側 安全性 ➝ 應用程式密碼

epower-pve211.png

輸入完名子後點擊產生

epower-pve212.png

紅框內的密碼就是冒號後面要輸入的

epower-pve213.png

執行檔案

輸入 postmap /etc/postfix/sasl_passwd

設定權限

輸入 cd /etc/postfix
輸入 chown postfix sasl_passwd*

重啟服務

輸入 systemctl reload postfix

測試寄信功能

下方的 test@test.com 要輸入收件人的 gmail
echo "Test mail from postfix" | mail -s "Test Postfix" test@test.com

查看測試信件

epower-pve214.png

備份成功及失敗時寄信測試

設定排程

左側 資料中心 ➝ 備份 ➝ 增加

epower-pve217.png

節點 : pve
儲存 : local
排程 : mon..fri 00:00 (週一至週五 00:00)
選擇模式 :包括以選取的 VM
發送郵件到 : 填寫收信者的 Email
Email : Notify always (不管成功失敗都會寄信)

epower-pve218.png

備份成功

epower-pve215.png

備份失敗

epower-pve216.png