Sending emails on Proxmox via CLI on tomleb's blog
I want to be able to send emails from my Proxmox node to notify me when my UPS is on battery.
If you already have an SMTP notification target set as the default notification mechanism, you can go straight to Sending an email.
Configuring SMTP notifications
First, we must configure an SMTP notification target and make it the default Notification matcher. Follow the steps below or alternatively take a look at the official Proxmox Notifications documentation.
Find the Notifications tab by going to Datacenter and then Notifications.
Next, add a new notification target by clicking Add and filling the form. The values depends on your email provider, so it is likely to differ from mine.
You can test this notification target by selecting it in the notification tab and clicking on the *Test button.
Finally, change the notification matcher default-matcher
to use this new SMTP
target. To do this, select the notification matcher from the notifications tab,
click on Modify and go to the Targets to notify tab.
That’s it, future notifications from Proxmox should now be sent to your configured email address.
Sending an email
To send an email from the CLI, you can pipe an email message to
/usr/bin/proxmox-mail-forward
command1. This will find the matcher and
notification target that we configured earlier - by reading from
/etc/pve/notifications.cfg
and /etc/pve/priv/notifications.cfg
- and will
read the email from stdin and send it to the target.
The email in stdin must follow this format:
Subject: <title>
<body>
Here’s a simple one liner:
printf 'Subject: Testing\n\nTesting an email with Proxmox\n' | proxmox-mail-forward
Or using a heredoc:
cat <<EOF | proxmox-mail-forward
Subject: UPS $UPSNAME update: $NOTIFYTYPE
Here are more information from that UPS:
$(upsc $UPSNAME)
EOF
-
The source code of proxmox-mail-forward can be found here. It would be nice if we had a bit more control over which matcher to use so that we don’t need to make this the default matcher. It would also be nice if it would work with all the supported notification types (eg: ntfy.sh, gotify, slack, etc) ↩︎
Contribute to the discussion in my public inbox by sending an email to ~tomleb/public-inbox@lists.sr.ht [mailing list etiquette]