Enhance possibilities for email notifications in openmediavault

By | 18. April 2015

Openmediavault is a very powerful free NAS administration system. In SYSTEM -> NOTIFICATION -> Tab NOTIFICATIONS you can decide which notifications you will receive by email. In my case i received a lot of notifications about cron jobs every day which was really annoying.
I found a thread in the openmediavault forum. The problem in my case was that the rsnapshots jobs weren’t reported in the log files anymore. So it wasn’t obvious for me if the jobs were really executed when i changed settings.

I found out that there is an easy way to redirect or even discard email notifications for (cron) jobs and still get syslog entries by using a simple Postfix configuration.

At first you have to create a file with name “header_checks” in /etc/postfix/
In my case i used the existing file “smtp_header_checks” for this:

cp /etc/postfix/smtp_header_checks /etc/postfix/header_checks

You can now specify a filter argument in postfix and define an action for matching emails:
nano /etc/postfix/header_checks

# Redirect cron emails
/^Subject:.*CRON-APT/ REDIRECT admin@XYZ.de
/^Subject:.*Anacron/ REDIRECT admin@ABC.de
/^Subject:.*cron.d/ REDIRECT admin@123.de

You have very flexible possibilities for defining filter rules. You can also easily avoid emails by using “DISCARD”. A rough introduction about the possibilities can be found here.
Finally you have to edit the Postfix main.cf to use “header_checks” by adding this line of code:
nano /etc/postfix/main.cf

header_checks = regexp:/etc/postfix/header_checks

Then you just have to restart Postfix to use this new configuration:

/etc/init.d/postfix restart

So you have a very flexible way of directing email notifications. You can even redirect the notifications to different email addresses depending on the severity of the notification.

You can check if the rules work by using :

echo "my message here" | mail -s"my subject here, e.g. CRON-APT" test_address_to_be_replaced_by_postfix_rule@xyz.de

I hope this is useful for somebody. You can read my original posting in the openmediavault forum here.