I've got a Hikvision network camera, which (only) can send email notifications and wanted to spice it up a little (that's why I started this whole gateway stuff).
So as we do have a signal web gateway running, let's just hook it up to a mail server.
I use postfix with pipes and aliases. You might want to setup a dedicated instance like I did or re-use/extend your running relay/server. This assumes an already running postfix.
Now there's also a dockerized version.
To process the mails received, we need some packages:
apt-get -y install mpack curl
We do process mails with this script (just make sure to adjust the variables below ## init
):
#!/bin/bash
## init
# define signal-weg-gateway url
SIGNAL_GW="http://signal-gateway.example.com"
# define recipient
RECIPIENT="+123456789"
set -e
# create unique folder per mail
UUID=$(mktemp -d /tmp/XXXXXXXXXX)
# save mail
cat > $UUID/mail
# check if we received plain text message or multipart message
if grep multipart/mixed $UUID/mail; then
# extract mail
munpack -C $UUID $UUID/mail
# get attachement if exists
FILE=$(find $UUID \( -name '*.jpg' -o -name '*.png' \))
# get text message if exists
MESSAGE=$(find $UUID -name '*.desc')
else
sed '1,/^$/d' $UUID/mail > $UUID/message
MESSAGE=$UUID/message
fi
# trigger webhook
if [ ! "$MESSAGE" == "" ]; then
REQUEST="curl -X POST -F to=$RECIPIENT -F message=$(cat $MESSAGE) $SIGNAL_GW"
if [ ! "$FILE" == "" ]; then
REQUEST="$REQUEST -F file=@$FILE"
fi
eval "$REQUEST"
fi
# delete mail
rm -rf "$UUID"
Place it somewhere reasonable like /usr/local/bin/mail2signal.sh
and make it executable.
Add something like this to your /etc/aliases
(do not forget to run newaliases
after each change):
mail2signal: "|/usr/local/bin/mail2signal.sh"