This HowTo will walk you through setting up your email alerts for Proxmox by enabling the use of an SNMP relay provided by Gmail. You will need to have a Gmail account and enable 2FA on that account.
SSH into proxmox node and become root user. Run the following commands to install the SASL authentication modules.
1
2
| apt update
apt install -y libsasl2-modules mailutils rsyslog
|
Enable 2FA for the gmail account that will be used by going to security settings
Create App Password For Your Account.
- Go to App Passwords
- Select app: Mail
- Select device: Other
- Type in: Proxmox or whatever you want here
Create SASL Authentication File and Hash It
1
2
3
4
5
| echo "smtp.gmail.com [email protected]:yourpassword" > /etc/postfix/sasl_passwd
chmod 600 /etc/postfix/sasl_passwd
postmap hash:/etc/postfix/sasl_passwd
|
Edit the Postfix Configuration File
1
| nano /etc/postfix/main.cf
|
Add/Modify the following:
1
2
3
4
5
6
7
8
| relayhost = smtp.gmail.com:587
smtp_use_tls = yes
smtp_sasl_auth_enable = yes
smtp_sasl_security_options =
smtp_sasl_password_maps = hash:/etc/postfix/sasl_passwd
smtp_tls_CAfile = /etc/ssl/certs/Entrust_Root_Certification_Authority.pem
smtp_tls_session_cache_database = btree:/var/lib/postfix/smtp_tls_session_cache
smtp_tls_session_cache_timeout = 3600s
|
Explanation of entries:
1
2
3
4
5
| relayhost = smtp-host.domain.com:587 >> SMTP relay server name and port
smtp_use_tls = yes >> Use Transport Layer Security (TLS) encryption
smtp_sasl_auth_enable = yes >> Enable SASL client-side authentication using username and password
smtp_sasl_password_maps = hash:/etc/postfix/sasl_passwd >> Lookup table containing username and password for authentication
smtp_tls_CApath = /etc/ssl/certs >> Directory containing Certificate Authority certificates that Postfix will use to verify remote SMTP server's certificates
|
My file looks like this when done:
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.example.local
mynetworks = 127.0.0.0/8
smtpd_banner = $myhostname ESMTP $mail_name (Debian/GNU)
biff = no
inet_interfaces = loopback-only
recipient_delimiter = +
compatibility_level = 2
# 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
# Gmail Config
relayhost = smtp.gmail.com:587
smtp_use_tls = yes
smtp_sasl_auth_enable = yes
smtp_sasl_security_options =
smtp_sasl_password_maps = hash:/etc/postfix/sasl_passwd
smtp_tls_CAfile = /etc/ssl/certs/Entrust_Root_Certification_Authority.pem
smtp_tls_session_cache_database = btree:/var/lib/postfix/smtp_tls_session_cache
smtp_tls_session_cache_timeout = 3600s
|
Change sasl_passwdand sasl_passwd.db Permissions
1
2
| chown root:root /etc/postfix/sasl_passwd /etc/postfix/sasl_passwd.db
chmod 0600 /etc/postfix/sasl_passwd /etc/postfix/sasl_passwd.db
|
Reload postfix:
Send Test Email
Check the Mail Log
1
| tail /var/log/mail.info
|
Fix From Name in Email
Install dependency:
1
| apt install postfix-pcre
|
Edit config:
1
| nano /etc/postfix/smtp_header_checks
|
Add
Change pve1-alert to what you want to see as the From name.
Hash the file:
1
| postmap hash:/etc/postfix/smtp_header_checks
|
Edit the postfix config:
1
| nano /etc/postfix/main.cf
|
Add this line:
1
| smtp_header_checks = pcre:/etc/postfix/smtp_header_checks
|
Reload postfix:
Resend Test Email