[Asterisk-Users] Receiving Faxes...

Gareth Blades list-asterisk at linguaphone.co.uk
Wed Apr 19 01:50:15 MST 2006


This is what I do and it works well. It uses the asterisk database so
you can define which printer the fax gets printed on and/or email
address the pdf gets mailed to.

[macro-fax]
exten => s,1,Set(FAXFILE=${UNIQUEID}.tif)
exten => s,2,Set(FAXOK=no)
exten => s,3,rxfax(/var/spool/asterisk-fax/${FAXFILE})
exten => s,4,Set(PRINTER=${DB(faxprinter/${MACRO_EXTEN})})
exten => s,5,GotoIf($["${PRINTER}" = "" ]?8)
exten => s,6,Set(FAXOK=yes)
exten => s,7,system(/usr/local/bin/printfax ${UNIQUEID} ${FAXFILE}
${PRINTER} "${CALLERIDNUM} ${CALLERIDNAME}")
exten => s,8,Set(EMAILADDR=${DB(faxemail/${MACRO_EXTEN})})
exten => s,9,GotoIf($["${EMAILADDR}" = "" ]?200)
exten => s,10,system(/usr/local/bin/mailfax ${UNIQUEID} ${FAXFILE}
${EMAILADDR} "${CALLERIDNUM} ${CALLERIDNAME}")
exten => s,11,Hangup
exten => s,108,Goto(201)
exten => s,111,Goto(201)
exten => s,200,GotoIf($["${FAXOK}" = "yes" ]?11)
exten => s,201,Set(EMAILADDR=defaultaddr at xxxxx.com)
exten => s,202,Goto(10)

[root at asterisk asterisk]# cat /usr/local/bin/printfax
#!/bin/sh
FAXID=$1
FAXFILE=$2
FAXPRINTER=$3
FAXSENDER=$4
DATETIME=`date +"%A %d %b %Y %H:%M"`
cd /var/spool/asterisk-fax
if [ -e $FAXFILE ]
then
  tiff2ps -2eaz -w 8.25 -h 11.5 $FAXFILE | lp -d $FAXPRINTER -

[root at asterisk asterisk]# cat /usr/local/bin/printfax
#!/bin/sh
FAXID=$1
FAXFILE=$2
FAXPRINTER=$3
FAXSENDER=$4
DATETIME=`date +"%A %d %b %Y %H:%M"`
cd /var/spool/asterisk-fax
if [ -e $FAXFILE ]
then
  tiff2ps -2eaz -w 8.25 -h 11.5 $FAXFILE | lp -d $FAXPRINTER -
fi
[root at asterisk asterisk]# cat /usr/local/bin/mailfax
#!/bin/sh
FAXID=$1
FAXFILE=$2
FAXRECIPIENT=$3
FAXSENDER=$4
DATETIME=`date +"%A %d %b %Y %H:%M"`
cd /var/spool/asterisk-fax
if [ -e $FAXFILE ]
then
  MAILFILE="$FAXID.mail"
  PAGES=$(tiffinfo $FAXFILE | grep "Page")
  DT=$(tiffinfo $FAXFILE | grep "Date")
  DTFAX=${DT#*:}
  COUNT=${PAGES#*-}
  echo "You have just recieved a new fax document." >$MAILFILE
  echo >>$MAILFILE
  echo "From        : $FAXSENDER" >>$MAILFILE
  echo "Received at : $DATETIME" >>$MAILFILE
  echo "Dated       : $DTFAX" >>$MAILFILE
  echo "Pages       : $COUNT" >>$MAILFILE
  echo >>$MAILFILE
  echo "The fax has been converted to an Acrobat .PDF and attached to
this email." >>$MAILFILE
  tiff2ps -2eaz -w 8.25 -h 11.5 $FAXFILE | ps2pdf - | mime-construct
--to $FAXRECIPIENT --subject "Fax Received from $FAXSENDER" --file
$MAILFILE --attachment $FAXID.pdf --type application/pdf --file -
#  tiff2pdf -p a4 $FAXFILE | mime-construct --to $FAXRECIPIENT --subject
"Fax Received from $FAXSENDER" --string "$BODY" --attachment $FAXID.pdf
--type application/pdf --file -
else
  MAILFILE="$FAXID.mail"
  echo "A call was received on your fax line however no fax was received
or there was an error." >$MAILFILE
  echo >>$MAILFILE
  echo "From  : $FAXSENDER" >>$MAILFILE
  echo "When  : $DATETIME" >>$MAILFILE
  mime-construct --to $FAXRECIPIENT --subject "Error receiving fax from
$FAXSENDER" --file $MAILFILE
  cat $MAILFILE
fi


On Tue, 2006-04-18 at 20:08, Christian Gröger wrote:
> Hi,
> 
> I am experimenting with receiving faxes in asterisk:
> 
> exten => in_fax,1,Macro(faxreceive)
> exten => in_fax,2,system(tiff2ps -2eaz -w 8.5 -h 11 ${FAXFILE} | ps2pdf 
> - ${FAXFILE}.pdf)
> exten => in_fax,3,system(cp ${FAXFILE}.pdf 
> /var/www/faxes/${CALLERID(number)}.pdf)
> exten => in_fax,4,system(mime-construct --to mail at server --subject "Fax 
> from ${CALLERID(number)} ${CALLERID(name)}" --attachment 
> ${CALLERID(number)}.pdf --type application/pdf --file ${FAXFILE}.pdf)
> exten => in_fax,5,system(rm ${FAXFILE} ${FAXFILE}.pdf)
> exten => in_fax,6,Hangup
> 
> That is an extension Freepbx made, with some extensions from me, because 
> FreePBX doesn't work well with mISDN... Wel, it receives faxes and it 
> saves them as an tif, it also converts them to a pdf file, but the other 
> commands aren't executed... why?
> 
> thanks for help
> _______________________________________________
> --Bandwidth and Colocation provided by Easynews.com --
> 
> Asterisk-Users mailing list
> To UNSUBSCRIBE or update options visit:
>    http://lists.digium.com/mailman/listinfo/asterisk-users




More information about the asterisk-users mailing list