Here is the first ever complete python script I wrote. This was done recently because I wanted a way to receive faxes via FreeSWITCH that I could manipulate and use for multiple fax lines and customers with a minimal amount of overhead. The script receives the fax using spandsp/mod_fax and then converts the fax image into a PDF file, and emails it to me.
This script is meant to be called from the FreeSWITCH dialplan XML, and requires that you have a recent build of FreeSWITCH, a working mod_fax installation, a working mod_python installation, and a functional ghostscript installation with the “ps2pdf” command.
I’ve tested this script to work on various builds of the May 2009 FreeSWITCH SVN trunk codebase, under FreeBSD 7.x, using a virtual server from the amazing VoIP provider Link2VoIP.com. It works great for receiving faxes in email and has no limitation of how many faxes it can receive at once (fax lines don’t ring busy unless FreeSWITCH runs out of CPU/capacity to keep handling them). On my Link2VoIP virtual server I was able to simultaneously send and receive 50 faxes to and from myself concurrently without anything crashing.
Once you have a working FreeSWITCH, with all of the above requirements met, create an extension similar to the following, which calls the script when the extension is called:
<condition field="destination_number" expression="^\*90012$">
<action application="set" data="recipient=YOU@YOURDOMAINHERE.com"/>
<action application="python" data="process-rxfax"/>
Set the recipient variable in dialplan to the email address you want the fax to get sent to. The SMTP server specified in the script must be able to relay mail to this email address.
Thanks to the amazing developers of FreeSWITCH and spandsp.
Comments/improvements are appreciated!
Get the script here.