diff --git a/README.md b/README.md index 3b8a482..9f33254 100644 --- a/README.md +++ b/README.md @@ -1,3 +1,21 @@ # hylafaxtoemail +Send faxes received from HylaFAX to an email address as PDFs -Send faxes received from HylaFAX to an email address as PDFs. \ No newline at end of file + sudo apt-get install sendemail libio-socket-ssl-perl libnet-ssleay-perl + + git clone https://github.com/signal-9/hylafaxtoemail.git + + cd hylafaxtoemail + +Edit `faxtoemail.sh` and fix your SMTP settings, directories, etc. +Edit `faxtoemail.service` and adjust your username accordingly. + + chmod +x faxtoemail.sh + sudo cp faxtoemail.service /etc/systemd/system/ + systemctl daemon-reload + systemctl enable faxtoemail.service + systemctl start faxtoemail + +To automatically remove converted PDFs older than 7 days, add to your crontab: + + 0 0 * * 0 find /your/pdf/directory/here/* -mtime +6 -type f -delete >/dev/null 2>&1 diff --git a/faxtoemail.service b/faxtoemail.service new file mode 100644 index 0000000..a2b8731 --- /dev/null +++ b/faxtoemail.service @@ -0,0 +1,13 @@ +[Unit] +Description=Fax to Email Script +After=network.target +StartLimitIntervalSec=0 + +[Service] +Type=simple +Restart=always +RestartSec=1 +ExecStart=/home/username/hylafaxtoemail/faxtoemail.sh + +[Install] +WantedBy=multi-user.target diff --git a/faxtoemail.sh b/faxtoemail.sh new file mode 100644 index 0000000..a7c7676 --- /dev/null +++ b/faxtoemail.sh @@ -0,0 +1,28 @@ +#!/bin/bash + +# HylaFAX recieved directory +TARGET=/var/spool/hylafax/recvq +# Directory you will have converted pdfs stored +PROCESSED=/home/username/pdfs +# Edit your SMTP server info as needed +SMTPFROM=user@email.org +SMTPTO=user2@email.org +SMTPSERVER=mail.email.org:587 +SMTPUSER=user@email.org +SMTPPASS=mysupersecurepassword +MESSAGEBODY="New Fax Recieved. Say whatever you want here." +SUBJECT="New Fax, or something" + +# Watch the target directory for new files, wait 5 +# minutes (about 20 pages worth), then convert to pdf and email the file. + +inotifywait -m -e create --format "%f" $TARGET \ + | while read FILENAME + do + echo Detected $FILENAME, converting to pdf and emailing + sleep 5m + tiff2pdf -o "$PROCESSED/$FILENAME.pdf" "$TARGET/$FILENAME" + wait + sleep 10s + sendEmail -f $SMTPFROM -t $SMTPTO -u $SUBJECT -m $MESSAGEBODY -s $SMTPSERVER -xu $SMTPUSER -xp $SMTPPASS -a "$PROCESSED/$FILENAME.pdf" + done