Created
August 28, 2015 07:20
-
-
Save stefb69/ab1bbb39453d37d54eb4 to your computer and use it in GitHub Desktop.
Mail to Fax gateway script for hylafax
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| #!/bin/sh | |
| # mail2fax reloaded | |
| # modified version working 100% by stefb (for europe) | |
| # This script allows you to send faxes through your HylaFAX box. | |
| # It uses mpack to strip out email attachments and sendfax to do | |
| # the fax delivery. | |
| ### Temporary dir stuff | |
| RANDOMFAX=/tmp/faxtmp.$(dd if=/dev/urandom count=1 2> /dev/null | cksum | cut -f1 -d" ") | |
| if [ ! -d "$RANDOMFAX" ] ; then | |
| mkdir $RANDOMFAX | |
| fi | |
| rm -f $RANDOMFAX/* | |
| ### Some makeup (maybe not necessary anymore) | |
| sed 's/multipart\/alternative/multipart\/mixed/' > $RANDOMFAX/_message_ | |
| JOBID=`grep -e "^subject:" -i $RANDOMFAX/_message_ | sed q | sed 's/^[^:]*: *//g'` | |
| TOLINE=`grep -e "^to:" -i $RANDOMFAX/_message_ | sed q` | |
| FROMLINE=`grep -e "^from:" -i $RANDOMFAX/_message_ | sed q` | |
| if [ "`echo $TOLINE | grep '<.*>'`" != "" ]; then | |
| TONUMBER=`echo $TOLINE| sed -e 's/.*<\(.*[^@]*\)@.*>.*/\1/'` | |
| else | |
| TONUMBER=`echo $TOLINE| sed -e 's/^[Tt]o://g' -e 's/[ ]*\(.*[^@]*\)@.*/\1/'` | |
| fi | |
| if [ "`echo $FROMLINE | grep '<.*>'`" != "" ]; then | |
| FROMPATH=`echo $FROMLINE| sed -e 's/.*<\(.*\).*>.*/\1/'` | |
| else | |
| FROMPATH=`echo $FROMLINE| sed -e 's/^[Ff]rom://g' -e 's/[ ]*\([^ ]*\).*/\1/'` | |
| fi | |
| ### Split message | |
| munpack -q -C $RANDOMFAX _message_ > /dev/null 2>&1 | |
| ### Delete all but the attachments | |
| rm -f $RANDOMFAX/_message_ | |
| rm -f $RANDOMFAX/*.desc | |
| ### Delivery time! | |
| echo sendfax -R -f "$FROMPATH" -s a4 -n -d "$TONUMBER" $RANDOMFAX/* >> /tmp/faxlog | |
| sendfax -R -f "$FROMPATH" -s a4 -n -d "$TONUMBER" $RANDOMFAX/* | |
| ### Remove temporary dir | |
| rm -rf $RANDOMFAX |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
I recently needed a way to send faxes quickly without dealing with outdated machines or complicated setups, and experimenting with a Mail to Fax gateway script made a huge difference. What struck me was how seamless the integration can be—once you set up the script, sending a fax directly from an email feels just like sending a regular message, but with all the formatting intact. I combined this with a service like https://mfax.to/, which simplifies sending from any device—phone, tablet, or computer—while keeping everything secure and HIPAA-compliant. It handles multiple file types, lets you scan or sign documents on the fly, and the delivery is almost instant. For anyone who needs reliable, paperless faxing, this combination made the process fast, predictable, and surprisingly stress-free.