Here is a sample Fax to Email dial plan example that uses the "tiff2pdf" application to convert the TIFF file to a PDF file.

= = = = = = = = = = = = = = = =


; ${ARG1} - Extension (we could have used ${MACRO_EXTEN} here as well
exten => s,1,DBput(LCR/${MACRO_EXTEN}=${CALLERIDNUM})
exten => s,2,Set(FAX_EMAIL=${ARG1})
exten => s,3,Answer
exten => fax,1,Goto(fax,${FAX_EMAIL},1)
exten => s,4,Wait(2)
exten => s,5,Dial(${ARG2},20,Tt) ; Ring the interface, 20 seconds maximum
exten => s,6,Goto(s-${DIALSTATUS},1)

exten => s,1,Set(FAXFILE=/var/spool/asterisk-fax/${UNIQUEID}.tif)
exten => s,2,Set(CELL=name@domain.com)
;exten => s,3,DBGet(EMAILADDR=extensionemail/${FAX_EMAIL})
exten => s,3,Set(EMAILADDR=${DB(extensionemail/${FAX_EMAIL})})
exten => s,4,rxfax(${FAXFILE})
exten => s,104,Set(EMAILADDR=name@domain.com); set default email account for invalid DID/email matches.
exten => s,105,Goto(4)

exten => _X.,1,Macro(faxreceive)
exten => h,1,system(/usr/local/sbin/mailfax ${FAXFILE} ${EMAILADDR} ${CELL} "${REMOTESTATIONID} ${CALLERIDNUM} ${CALLERIDNAME}")
exten => i,1,Hangup
exten => t,1,Hangup

Below is the actual script called upon hungup after fax transmission. This script uses tiff2pdf routine which is provided with libtiff package to convert standard tiff fax image to pdf.
Then, we use “mutt” Unix command to email the image to the recipient email and optionally to send notification to his/her sms account.


/usr/local/bin/tiff2pdf -p letter $FAXFILE -o $FAXFILE.pdf
mutt -a $FAXFILE.pdf -s "FAX from $FAXSENDER" $RECIPIENT < /var/spool/asterisk-fax/fax.txt
# mutt -s "You have received fax from $FAXSENDER" $CELL < /var/spool/asterisk-fax/sms.txt
rm $FAXFILE.pdf