Search:
     
3CX Phone System for Windows Download the Free Edition

Asterisk Fax to email

Asterisk Fax to email example


Description

This is a working example of a fax to email implementation for asterisk

Packages used

  • Spandsp (receive faxes)
  • Bash (script)
  • sendEmail (sending emails) - http://caspian.dotconf.net/menu/Software/SendEmail/

Overview
The idea is quite simple. I needed a fax server that could send an email with attachment when a fax is received. Fax comes in on dedicated extensions (I am not doing any fax detection as I am using SIP only) , using the dialplan the fax is received and saves to a tiff file. The email address, To name and the hosting companys name is stored in the asterisk db using database put from the management console.

These are retrieved when the call is received and passed along to a bash script which generates an email and sends it with the fax as an attachment using sendEmail (opensource per script)

Configuration files


Extensions.conf


[macro-faxreceive]
 exten => s,1,SetVar(FAXFILE=/var/spool/asterisk/fax/${CALLEDFAX}/${UNIQUEID})
 exten => s,2,DBGet(EXTEMAIL=${MACRO_EXTEN}/xEmail)
 exten => s,3,NoOP()
 exten => s,4,DBGet(EXTNAME=${MACRO_EXTEN}/xName)
 exten => s,5,NoOP()
 exten => s,6,DBGet(EXTCOMPANY=${MACRO_EXTEN}/xCompany)
 exten => s,7,rxfax(${FAXFILE}.tif)
 exten => s,103,SetVar(EXTMAIL=fax@company.com)
 exten => s,104,Goto(7)
 exten => s,105,SetVar(EXTNAME=Unknown)
 exten => s,106,Goto(7)
 exten => s,107,SetVar(EXTCOMPANY=Company)
 exten => s,108,Goto(7)

[fax]
 exten => 123456789,1,Macro(faxreceive)

 exten => h,1,System(/var/lib/asterisk/scripts/mailfax "${CALLERIDNUM}" "${CALLEDFAX}" "${EXTNAME}" "${EXTEMAIL}" "${FAXFILE}" "${EXTCOMPANY}")

[default]

  exten => 123456789,1,SetVar(CALLEDFAX=${EXTEN})
  exten => 123456789,2,Answer
  exten => 123456789,3,Goto(fax,${EXTEN},1)

Bash Script

#!/bin/bash
echo Received paramters $1 $2 $3 $4 $5 $6 >>/var/log/faxmail.log
DATETIME=`date +"%A %d %b %Y %H:%M"`
if [ -e $5.tif ]
then
 echo fax file $5.tif found. Sending email to $4 .... >>/var/log/faxmail.log
 PAGES=$(tiffinfo $5.tif | grep "Page")
 DT=$(tiffinfo $5.tif | grep "Date")
 DTFAX=${DT#*:}
 COUNT=${PAGES#*-}
 rm -f $5.txt
 echo Dear $3, >>$5.txt
 echo >>$5.txt
 echo You have just recieved a new fax document. Details as follow >>$5.txt
 echo >>$5.txt
 echo "From  : "$1 >>$5.txt
 echo "To    : "$2 >>$5.txt
 echo "When  : "$DATETIME '['$DTFAX' ]'>>$5.txt
 echo "Pages : "$COUNT>>$5.txt
 echo  >>$5.txt
 echo >>$5.txt
 echo You can view your faxes online by visiting https://fax.abc.com. Your login name is the full fax number >>$5.txt
 echo  >>$5.txt
 echo Thank you for using $6 >>$5.txt
 echo sendEmail -f $1@fax.abc.com -t $4 -u "New fax received" -a $5.tif -o message-file=$5.txt \ >> /var/log/faxmail.log
 echo "<<<<<<<<<<<<<<<<<<<<---------------->>>>>>>>>>>>>>>>>>>>>>>>>" >> /var/log/faxmail.log
 /usr/local/bin/sendEmail -l /var/log/sendEmail.log -q -s 195.219.151.8 -f $1@fax.abc.com -t $4 -u "New fax received" -a $5.tif -o "message-file=$5.txt"
else
 rm -f $5.txt
 echo Dear $3, >>$5.txt
 echo >>$5.txt
 echo A call was recieved on your fax line, however no fax was recieved or the attempt failed. Details as follow >>$5.txt
 echo >>$5.txt
 echo "From  : "$1 >>$5.txt
 echo "To    : "$2 >>$5.txt
 #echo $DATETIME >>$5.txt
 echo "When  : "$DATETIME >>$5.txt
 #echo "Pages : "$COUNT>>$5.txt
 echo  >>$5.txt

 echo This notification is for your conveniance, if it is not required please notify your system administrator >>$5.txt
 #echo >>$5.txt
 #echo You can view your faxes online by visiting https://fax.abc.com. Your login name is the full fax number >>$5.txt
 echo  >>$5.txt
 echo Thank you for using $6 >>$5.txt
 echo sendEmail -f $1@fax.abc.com -t $4 -u "Fax reception failed" -o message-file=$5.txt \ >> /var/log/faxmail.log
 echo "<<<<<<<<<<<<<<<<<<<<---------------->>>>>>>>>>>>>>>>>>>>>>>>>" >> /var/log/faxmail.log
 /usr/local/bin/sendEmail -l /var/log/sendEmail.log -q -s 195.219.151.8 -f $1@fax.abc.com -t $4 -u "Fax reception failed" -o "message-file=$5.txt"
 exit
fi

Page created by : Umar Sear


See also

Created by: usear,Last modification on Sat 07 of Aug, 2010 [16:00 UTC] by michael_mavroudis


Please update this page with new information, just login and click on the "Edit" or "Discussion" tab. Get a free login here: Register Thanks! - support@voip-info.org

Page Changes | Comments

 





Search: