[Guide] Email to Growl relay


Recommended Posts

Instructions for an Email-to-Growl relay to get growl notifications from any app that supports email alerts, like unRAID.

I have this setup on a pi but any debian (and maybe other) distros should work.

 

This is a dirty first draft so if you're one of the two people who still use growl and run into difficulty let me know and I'll clean it up.

 

NOTE: This assumes you have Growl setup and working on all client machines. I'm not sure where to download 2.x from anymore. If I find the installer I'll make it available.

 

CAUTION: This assumes the target machine DOES NOT have SMTP ports open to the internet. This is an insecure local-only setup.

 

This Guide Assumes:

Local Network: 10.0.1.0/24

Docker Network: 172.17.0.0/24

Install host: pi.lan

Install host IP: 10.0.1.10

Install user/group: pi/pi

Growl Client IPs: 10.0.1.2, 10.0.1.3

Growl Password: my_password

unRAID hostname: nas.lan

 

Customize as needed.

 

## References

https://wiki.debian.org/Exim

https://geekthis.net/post/exim-process-mail-script/

https://askubuntu.com/questions/927056/disable-ipv6-in-exim4

 

 

## Install pip

sudo apt update
sudo apt install python-pip

 

## Make sure it's up to date

sudo pip install --upgrade pip

 

## Install gntp (python library for growl notifications)

sudo pip install gntp

 

## Create a notifier script

sudo emacs /usr/bin/growl-notify.py

## Paste:

# use standard Python logging
import sys
import logging
logging.basicConfig(level=logging.INFO)
import gntp.notifier

# takes host-ip (maybe hostname) and password in argv,
# e.g growl-notify.py 10.0.1.1 my_password

growl = gntp.notifier.GrowlNotifier(
    applicationName = sys.argv[3],
    notifications = [sys.argv[4],],
    defaultNotifications = [sys.argv[4]],
    hostname = sys.argv[1],       # Here enter your Mac IP addresses
    password = sys.argv[2]        # Here enter your growl password
)
growl.register()

# Send one message
growl.notify(
    noteType = sys.argv[4],
    title = sys.argv[5],
    description = sys.argv[6],
    icon = sys.argv[7],
    sticky = True,
    priority = 1,
)

 

 

## Exim

## Should be installed by default on debian so reconfigure

sudo dpkg-reconfigure exim4-config

## Select options:

  1. internet site; mail is sent and received directly using SMTP
  2. pi.lan
  3. <leave blank>
  4. pi.lan
  5. <leave blank>
  6. 10.0.1.0/24; 172.17.0.0/24
  7. No
  8. mbox format in /var/mail/
  9. Yes (split)

 

## Create exim router

## Forwards any mail addressed to [email protected] to the transport

sudo emacs /etc/exim4/conf.d/router/101_growl_forward

## Paste:

growl_forward:
        driver = accept
        local_part_prefix = growl
        transport = transport_growl_forward

 

## Create transport

## This will forward to our shell script

sudo emacs /etc/exim4/conf.d/transport/101_custom-growl_forward

## Paste:

transport_growl_forward:
        driver = pipe
        command = /usr/local/bin/growl_forward.sh
        user = pi
        group = pi

 

## Create shell script

sudo emacs /usr/local/bin/growl_forward.sh

## Paste:

#!/bin/bash                                                                                                                                                                                                                        

## User Config                                                                                                                                                                                                                     

# Touch this file (as root) then chown it to whatever user this runs as                                                                                                                                                             
LOG_FILE="/var/log/growl_forward.log"

# List of growl clients by IP                                                                                                                                                                                                       
GROWL_CLIENTS=(
    "10.0.1.2"
    "10.0.1.3"
)

# Hardcoded Growl password (do we really need security?)                                                                                                                                                                                      
GROWL_PASSWORD="my_password"

## Main                                                                                                                                                                                                                            
MESSAGE=$(cat)

echo ' ' >> $LOG_FILE
date >> $LOG_FILE

echo "MESSAGE: ${MESSAGE}" >> $LOG_FILE

# Parse from                                                                                                                                                                                                                       
FROM=$(grep 'From' <<< ${MESSAGE})
FROM=$(head -1 <<< $FROM)
FROM=${FROM#'From: '}

# Parse subject                                                                                                                                                                                                                     
SUBJECT=$(grep 'Subject' <<< ${MESSAGE})
SUBJECT=$(head -1 <<< $SUBJECT)
SUBJECT=${SUBJECT#'Subject: '}
SUBJECT=${SUBJECT/': '/' - '}

# Headings                                                                                                                                                                                                                         
#                                                                                                                                                                                                                                  

HEADING=" "

# For Unraid use Importance
if [[ $FROM -eq "[email protected]" ]]; then
    HEADING=$(grep 'Importance' <<< ${MESSAGE})
    HEADING=${HEADING#'Importance: '}
    HEADING=${HEADING^^}
    HEADING="[$HEADING]"
fi

# Parse description                                                                                                                                                                                                                 
DESCRIPTION=$(grep 'Description' <<< ${MESSAGE})
DESCRIPTION=${DESCRIPTION#'Description: '}

for growl_client in ${GROWL_CLIENTS[*]}
do
    echo "*** EXECUTING: /usr/bin/python /usr/bin/growl-notify.py ${growl_client} '*********' \"$SUBJECT\" \" \" \"$HEADING\" \"$DESCRIPTION\" \"\" " >> $LOG_FILE
    /usr/bin/python /usr/bin/growl-notify.py ${growl_client} "${GROWL_PASSWORD}" "$SUBJECT" " " "$HEADING" "$DESCRIPTION" ""
done

exit 0

## Make it executable

sudo chmod a+x /usr/local/bin/growl_forward.sh

 

## Disable ipv6 to eliminate SIGNIFICANT delays caused by connection attempts to nonexistent network

sudo cp /etc/exim4/conf.d/main/02_exim4-config_options  /etc/exim4/conf.d/main/02_exim4-config_options.orig
sudo emacs  /etc/exim4/conf.d/main/02_exim4-config_options

## Paste this after the header:

disable_ipv6=true

## Allow unqualified recipients (missing domain) defaulting to local domain
recipient_unqualified_hosts = *
qualify_recipient = pi.lan

 

## Reconfigure and restart exim

sudo update-exim4.conf
sudo service exim4 restart

 

## Verify ipv6 is disabled

sudo apt install net-tools
netstat -tulpn | grep :25

# You should only see ipv4 addresses

 

## Log file

sudo touch /var/log/growl_forward.log
sudo chown pi:pi /var/log/growl_forward.log
sudo chmod a+r /var/log/growl_forward.log

 

## Tail to monitor:

sudo tail -f /var/log/exim4/mainlog /var/log/syslog /var/log/growl_forward.log

 

## Now any emails to [email protected] should be broadcast as Growl notifications

 

## Add Growl alerts to unRAID

# Settings -> Notifications -> SMTP

1005978992_ScreenShot2020-12-15at11_04_36AM.thumb.png.6f6340a75244829fedfd2dc537af7e66.png

 

## Click

APPLY

 

## then click

TEST

 

## and watch the tail above for any errors

Edited by CS01-HS
Link to comment

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.