Skip to main content

PVE Postfix由Gmail寄發信件

運行環境
  • PVE 7
安裝相關套件
apt install libsasl2-modules -y
設定Postfix

編輯/etc/postfix/main.cf

# GMail Setting
relayhost = [smtp.gmail.com]:587
#  use tls
smtp_use_tls=yes
# use sasl when authenticating to foreign SMTP servers
smtp_sasl_auth_enable = yes
# path to password map file
smtp_sasl_password_maps = hash:/etc/postfix/sasl_passwd
# list of CAs to trust when verifying server certificate
smtp_tls_CAfile = /etc/ssl/certs/ca-certificates.crt
# eliminates default security options which are imcompatible with gmail
smtp_sasl_security_options = noanonymous
smtp_always_send_ehlo = yes
smtpd_relay_restrictions = permit_mynetworks permit_sasl_authenticated reject_unauth_destination

編輯 /etc/postfix/sasl_passwd

[smtp.gmail.com]:587 <google信箱>:<應用程式密碼>

需到 Google 帳號產生應用程式密碼

更改檔案權限

postmap /etc/postfix/sasl_passwd
cd /etc/postfix
chown postfix /etc/postfix/sasl_passwd*

/etc/init.d/postfix reload
測試寄件
echo “Test mail from postfix” | mail -s “Test Postfix” test@test.com