Setting up Email Alerts in Proxmox
https://technotim.live/posts/proxmox-alerts/
Install Prerequisites and Configure Postfix
-
Install prerequisites
apt updateapt install -y libsasl2-modules mailutils -
Set up an App Password on your sender account (Gmail in this case) - https://myaccount.google.com/apppasswords
-
Configure Postfix
echo "smtp.gmail.com your-email@gmail.com:YourAppPassword" > /etc/postfix/sasl_passwd -
Set/update permissions for the sasl_passwd file
chmod 600 /etc/postfix/sasl_passwd -
Hash the file
postmap hash:/etc/postfix/sasl_passwd -
Verify that the hash .db file was created
cat /etc/postfix/sasl_passwd.db -
Edit the Postfix configuration
nano /etc/postfix/main.cf -
Add the following lines at the end:
Also comment out the existing# google mail configuration 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 = 3600srelayhost =line -
Reload Postfix
postfix reload -
Send a test email using the following command:
echo "This is a test message sent from postfix on my Proxmox Server" | mail -s "Test Email from Proxmox" your-email@gmail.com
Fix/Change the From: Name from "root"
-
To fix/change the From: name to show as something other than "root", update and install the PCRE pre-requisite
apt updateapt install postfix-pcre -
Edit the SMTP header checks file
nano /etc/postfix/smtp_header_checksThe email address doesn't matter because it's going to get overwritten by RicicaHomelabLogs@gmail.com, so only the name will change./^From:.*/ REPLACE From: pve1-alert <pve1-alert@something.com> -
Hash the file
postmap hash:/etc/postfix/smtp_header_checks -
Check the contents of the hashed file
cat /etc/postfix/smtp_header_checks.db -
Edit the Postfix config file to add the smtp_header_checks parameter
nano /etc/postfix/main.cf -
Add the smtp_header_checks parameter to the end of the file:
smtp_header_checks = pcre:/etc/postfix/smtp_header_checks -
Reload Postfix for the changes to take effect
postfix reload -
Re-use the previous command to verify the changes took effect
echo "This is a test message sent from postfix on my Proxmox Server" | mail -s "Test Email from Proxmox" your-email@gmail.com