How to Configure Email Notifications in Proxmox

post-thumb

Photo by Sitthiphong from iStock

Table Of Contents

Out of the box Proxmox requires some configuration in order to receive email notifications. Email notifications are important if you wish to receive notifications about failed jobs such as backup jobs as well as other system issues. Since having a successful backup process is very important, notifications are critical to ensure you are aware that there is a problem you need to investigate.

Before Getting Started

I will be using Gmail as the example email account. You will need to create an app password for Gmail before you can send email notifications since many apps do not support two factor authentication. You may follow Google’s instructions if you are uncertain how to create an app password.

You will need to either open the “Shell” on the Proxmox web interface or log in via SSH to your Proxmox server to perform the remaining steps in this guide. I am going to assume you are logged in as the root user. Otherwise, you will need to use an account with sudo privileges.

Install Required Packages

If you are using your Gmail account for email notifications (or other email accounts which need the SASL module to authenticate), you need to install the libsasl2-modules package since it is not included in Proxmox by default:

apt install libsasl2-modules

Set up the Gmail Credentials

Run the command below to open a command line text editor to create a new sasl_passwd file:

nano /etc/postfix/sasl_passwd

Substitute your email address and app password below and save the file by pressing “Ctrl + O” and “Enter”. Press “Ctrl + X” to exit:

smtp.gmail.com [email protected]:app_password

Note

It is possible to create a file and insert contents with a single command such as echo "smtp.gmail.com [email protected]:app_password" > /etc/postfix/sasl_passwd, but if you do so, that command will show up in your command history and expose your password. You will have to clear out the command using the history command.

Now you need to hash the password so it is better secured:

postmap hash:/etc/postfix/sasl_passwd

The previous command will generate a sasl_passwd.db file. Set the permissions on the sasl_passwd.db file to only allow the root user read/write access to the file:

chmod 600 /etc/postfix/sasl_passwd.db

You should now remove the /etc/postfix/sasl_passwd file since it contains the clear text password:

rm /etc/postfix/sasl_passwd

I have seen instructions online which do not mention removing the sasl_passwd file. Even though they limit the permissions to just the root user, it is still best to not leave the clear text password on the system.

Edit the main.cf File

Open the main.cf file for editing:

nano /etc/postfix/main.cf

To prevent a warning message when reloading the postfix configuration, you should remove or comment out the line which says relayhost = by adding a # to the beginning of the line like so:

#relayhost =

The reason you will see a warning message is because relayhost will be specified when copying/pasting the Gmail configuration below.

Add the following text to the end of the main.cf file:

# Gmail 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 = 3600s

Reload Postfix and Test Sending an Email

Finally, you need to reload postfix by running the following command:

postfix reload

You may send a test email to verify your configuration is working properly. It is ok if you wish to use the same Gmail account to test the email notifications:

echo "Test message" | mail -s "Test Subject" [email protected]

Tip

When sending the test email, if the mail command displays -bash: mail: command not found, you will need to install mailutils by using the command: apt install mailutils.

comments powered by Disqus

You May Also Like