Enhance possibilities for email notifications

  • Hi there,
    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 one suggestion to eliminate these emails by adding >/dev/null to the specific file in /etc/cron.d. 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:

    Code
    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

    Code
    # 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

    Code
    header_checks = regexp:/etc/postfix/header_checks


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

    Code
    /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 :

    Code
    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.

Jetzt mitmachen!

Sie haben noch kein Benutzerkonto auf unserer Seite? Registrieren Sie sich kostenlos und nehmen Sie an unserer Community teil!