login | register
Fri 10 of Oct, 2008 [22:59 UTC]

voip-info.org

Discuss [7] History

Asterisk Fax to email

Created by: usear,Last modification on Sun 25 of Nov, 2007 [18:42 UTC] by abalashov

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


Comments

Comments Filter
222

333make spandsp

by tran_thanh20, Wednesday 18 of April, 2007 [11:18:43 UTC]
in the install proccess,i was fail:

Making all in src
make1: Entering directory `/usr/src/iaxmodem-0.0.14/lib/spandsp/src'
cd .. && /bin/sh /usr/src/iaxmodem-0.0.14/lib/spandsp/config/missing --run autoheader
Can't locate object method "path" via package "Autom4te::Request" at /usr/bin/autom4te line 81.
autoheader: /usr/bin/autom4te failed with exit status: 1
make1: *** ../config-h.in Error 1
make1: Leaving directory `/usr/src/iaxmodem-0.0.14/lib/spandsp/src'
make: *** all-recursive Error 1

Can you help me how to solving it?
222

333Question about the System Call in this example

by gbaker, Friday 16 of March, 2007 [16:23:41 UTC]
I'm running Trix-box version 2.0.

I've added the above configuration to my extensions_additional.conf

Everything seems to work, the tiff file is generated and stored in the /var/spool/asterisk/fax directory with the appropriate name given. However, the call to System doesn't seem to be working. No matter what I put in there, it doesn't seem to work, I tried the bash routine listed. Itried creating a routine that did nothing but create another test file, I even tried replacing it with /bin/touch 'file' and the file doesn''t get created.

Is ther any setup configuration needed to get the System function to work?


222

333Question about the System Call in this example

by gbaker, Friday 16 of March, 2007 [16:03:25 UTC]
I'm running Trix-box version 2.0.

I've added the above configuration to my extensions_additional.conf

Everything seems to work, the tiff file is generated and stored in the /var/spool/asterisk/fax directory with the appropriate name given. However, the call to System doesn't seem to be working. No matter what I put in there, it doesn't seem to work, I tried the bash routine listed. Itried creating a routine that did nothing but create another test file, I even tried replacing it with /bin/touch 'file' and the file doesn''t get created.

Is ther any setup configuration needed to get the System function to work?


222

333Pages bug

by masterbase, Thursday 06 of April, 2006 [01:41:32 UTC]
The bash script above to extract the amount of pages works fine, as long the fax is not longer then one page. When its longer $COUNT is something like that: "1 Page 2-2".
I added a while loop that runs COUNT=${COUNT#*-} until in $COUNT there is no more "Page" in $COUNT.

The script looks like this:
PAGES=$(tiffinfo $5.tif | grep "Page")
COUNT=${PAGES#*-}

while echo $COUNT | grep -q "Page"
do
COUNT=${COUNT#*-}
done

maby there is a simpler or better way to do this, but this works

if somebody knows a simpler way please tell it to me

Peter
222

333Efax

by mike240se, Wednesday 29 of March, 2006 [23:32:02 UTC]
Could something like this be used for my company to set up our own efax system rather than paying efax or similiar company? How are you doing the lines? 1 Line connected to asterisk with distinctive ring? Or a sip account with many DID's??? Is this the best way to do an efax system or do you know of a better way?
222

333Not necessarily

by FlyingAvatar, Tuesday 31 of January, 2006 [22:16:03 UTC]
Since Asterisk doesn't write any files directly to /var/spool/asterisk, I feel it is more correct to create a /var/spool/asterisk/fax directory. As you'll notice there are other sub-folders for spooled voicemail and outgoing calls.
222

333rowi.net

by , Monday 14 of February, 2005 [11:48:55 UTC]
exten => s,1,SetVar(FAXFILE=/var/spool/asterisk/fax/${CALLEDFAX}/${UNIQUEID})

should be

exten => s,1,SetVar(FAXFILE=/var/spool/asterisk/fax${CALLEDFAX}/${UNIQUEID})

since it contains a not needed "/".

Rolf