digiMoot:

Proxmox: Setup Email Service

Proxmox Setup Email ServiceGetting email notifications when Proxmox when backups or drives fails is an important part of monitoring that status of your Proxmox setup and virtual machines. This Proxmox: Setup Email Service article will walk you through setting up an email notification service so that you can receive messages from your Proxmox setup when something goes wrong and then jump into action. Proxmox  can let you know when backups succeed or fail or when you are having health issues with a ZFS drive. This article will use gmail as an example, but it you know the settings for

This is part of digiMoot’s series of articles on Proxmox installations, configurations and setup.

Install Prerequisites

Okay, let’s get started with this Proxmox: Setup Email Service article. This article will be done mostly from the command prompt. You need to get to the Proxmox shell, either through the webUI or connect via SSH.

Once at the shell, we will need to install the prerequisites with the following commands:

apt update

apt install -y libsasl2-modules

Generate 2FA Password (Optional)

The account I use doesn’t have 2FA but yours might. If you do, you will first have to generate a password to your email specific to Proxmox. To do this, login to your email account and then access your account password page. Add a custom application (select other), name it, and then generate a password. Copy and paste this password somewhere for use below.

Proxmox Generate Gmail 2FA Password

Setup Postfix

The next thing we need to do is to configure the Postfix service. We need to edit the Postfix config file, but first lets back it up with this command:

cp /etc/postfix/main.cf /etc/postfix/main_bak.cf

Once it’s backed up, let get in there and edit it. I use nano and so run the following command, but you can use an editor of your choice:

nano /etc/postfix/main.cf

 We will want to add the following, to the end of the file:

relayhost = [smtp.gmail.com]:587
smtp_use_tls = yes
smtp_sasl_auth_enable = yes
smtp_sasl_security_options = noanonymous
smtp_sasl_password_maps = hash:/etc/postfix/sasl_passwd
smtp_tls_CAfile = /etc/ssl/certs/ca-certificates.crt

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

In this file we have to be careful not to duplicate any lines we are adding with those already in the file. Check each line that has been added and if that line exists already, you will need to comment out the line that was already in the file by adding a ‘#’ to that start of the line. You wll notice that, in the example image below, I had to comment out the relayhost = line.

Proxmox Email Service

Once you’re done save the file and exit (in nano Ctrl-X and then ‘Y’).

You may have noticed that this file links to a sasl_passwd file. This file will store the email address and password for your email and this is what we will edit next:

nano /etc/postfix/sasl_passwd

In this file you will need to enter your credentials for you email, like the example below. Obviously you will need to replace ‘EMAILADDRESS’ with your email address and ‘PASSWORD’ with your password. Remember that if you used 2FA above, you will need to use the password generated in hat optional step.

[smtp.gmail.com]:587    EMAILADDRESS@gmail.com:PASSWORD

Once you’ve put your credentials in this file, then we will need to set the securities properly to protect your password. Run the following command.

chmod 600 /etc/postfix/sasl_passwd

Now lets update the postmap table with this new information by running:

postmap /etc/postfix/sasl_passwd

Now we can restart the postfix service:

systemctl restart postfix.service

Test Email Service

Now things should be ready to go, but lets give it a test. First lets send a test email with the mail service, using the following command (replacing the email address with the test recipient):

echo "Test mail from Proxmox" | mail -s "Test Proxmox" email@gmail.com

Check your email and you should see a message there if everything is working. If it is, we can also test if from PVE with the following:

echo "test" | /usr/bin/pvemailforward

Adding an Email to your Backup Tasks

Alright, now the important part is to make sure your email address is listed on your backup tasks. For this part you can leave the command prompt and head back to the Proxmox WebUI.

Click on DataCenter -> Backup and then select your backup task. Click edit and then in the top right of the window there will be a field which says ‘Send email to:”. You can enter the address of the email you wish to send to.

Proxmox Email Backup Task

Conclusion

Alright! That’s it! You’ve completed this Proxmox: Setup Email Service article and now have notifications configured for your backup tasks!

Happy Proxmoxin’!

Sources:
https://forum.proxmox.com/threads/get-postfix-to-send-notifications-email-externally.59940/
https://crepaldi.us/2021/03/07/configuring-e-mail-alerts-on-your-proxmox/

Liked it? Take a second to support digiMoot on Patreon!

Leave a Reply

Your email address will not be published. Required fields are marked *