Home » Technology » The Last Frontier: Handling Incoming Faxes with Asterisk

The Most Versatile VoIP Provider: FREE PORTING

The Last Frontier: Handling Incoming Faxes with Asterisk

We've covered lots of Asterisk® territory these past few months, but one of the real stumbling blocks has been reliable incoming fax support. Yes, Asterisk has some fax support built into the product; however, to use it you have to invest in Digium® hardware. Not that we're cheap or anything (we are actually!), but we wanted a fax solution that didn't rely on hardware. Stated another way, we wanted a pure software solution to faxing just like Asterisk provides a pure software solution to PBX telephony for those that want to use it. And we wanted reliable delivery of faxes using VoIP lines including IAX and SIP trunks, not just Ma Bell's PSTN lines. Well, we've finally found a solution, and it works reliably with Asterisk@Home 1.5 as well as Asterisk@Home 2.x. For those not using Asterisk@Home, the solution we're covering works reliably with Asterisk 1.09 as well as Asterisk 1.2 and 1.2.1. This tutorial assumes you're using Asterisk@Home, but the concepts will work equally well with "pure Asterisk" assuming you know what you're doing.

2008 Update: This article has been updated to support Asterisk 1.4. Click here for the latest article.

2011 Update: This article has been updated to support Asterisk 1.8 using HylaFax, AvantFax, and IAXmodem. Click here for the latest article.

The way this works is pretty straightforward. A fax machine calls your regular Asterisk phone number, no dedicated fax line required. When Asterisk answers the call, it listens for a fax tone. If it hears one, it reroutes the incoming call to a context which then processes the incoming fax. The fax is saved as a TIFF image, converted to a PDF document, and emailed to the address specified in your Asterisk@Home setup: AMP->Setup->General Settings. If a fax tone isn't detected, the call is processed as an incoming voice call according to the rules you've set up for incoming calls.

Prerequisites. As previously noted, you won't need any special hardware to make our incoming fax solution work with Asterisk. All you need is Asterisk@Home and Newman Telecom's NVfaxdetect, which is FREE for the downloading. You'll also need the Fax-to-PDF conversion tools which are included with Asterisk@Home. Your system also must be configured to send emails reliably. If you followed our tutorial for setting up your Asterisk@Home system, you should be all set. Otherwise, start there in the Activating Email Delivery of VoiceMail Messages section. Finally, if you're using an IAX or SIP trunk, you'll need a line from a VoIP provider with an uncompressed codec (such as ulaw), and you need an ITSP that knows what it's doing and supports incoming faxes. HINT: TelaSIP lines work. BroadVoice lines usually don't.


An equally important requirement for this project is following along carefully with this tutorial. We're going to be recompiling a modified Asterisk as part of this project and, if you screw it up by not paying careful attention to the details, not only will your system not accept faxes, it probably won't accept phone calls either when we're finished. Having said that, there is nothing hard about this project. You just need to type carefully and not skip any steps. So let's get started.

Installing Fax-to-PDF Conversion Tools. Let's begin with the easy stuff. First, you'll need to install the Fax-To-PDF conversion tools that are already scripted in Asterisk@Home. Log in to your server as root. At the command prompt, type install-pdf. Your system will whir away for a couple minutes after which you'll get a completed message that looks something like this:

Running Transaction
Installing: xorg-x11-font-utils ######################### [1/8]
Installing: ttmkfdir ######################### [2/8]
Installing: xorg-x11-xfs ######################### [3/8]
Installing: chkfontpath ######################### [4/8]
Installing: urw-fonts ######################### [5/8]
Installing: VFlib2 ######################### [6/8]
Installing: ghostscript-fonts ######################### [7/8]
Installing: ghostscript ######################### [8/8]

Installed: ghostscript.i386 0:7.07-33
Dependency Installed: VFlib2.i386 0:2.25.6-25 chkfontpath.i386 0:1.10.0-2 ghostscript-fonts.noarch 0:5.50-13 ttmkfdir.i386 0:3.0.9-14.1.EL urw-fonts.noarch 0:2.2-6.1 xorg-x11-font-utils.i386 0:6.8.2-1.EL.13.20 xorg-x11-xfs.i386 0:6.8.2-1.EL.13.20
Complete!

For those running Asterisk with flavors of Linux other than CentOS, the install command you'll need above is yum -y install ghostscript.

Routing Your Incoming Faxes. To specify where you want incoming faxes delivered, start up the Asterisk Management Panel (AMP) by pointing a web browser to the IP address of your Asterisk server. Then choose AMP->Setup->General Settings. In the Fax Machine section, leave the extension of fax machine set to System. For the email fax delivery address, enter a valid email address where you want the PDF copies of faxes to be sent. Click the Submit Changes button and then click the red bar to reload Asterisk.


Downloading NVfaxdetect. Log in to your Asterisk server as root, stop Asterisk, and download NVfaxdetect using the following commands:

amportal stop
cd /usr/src/asterisk/apps
wget http://www.newmantelecom.com/download/asterisk/faxdetect/1.0.6/app_nv_faxdetect.c

NOTE: Some intermittent problems have been reported downloading the source code from Newman Telecom. If you have a problem, you can download the patched source code directly from Nerd Vittles. Here's the link for Asterisk@Home 1.5 systems:

wget http://nerdvittles.com/aah15/app_nv_faxdetect.c

And here's the link for Asterisk@Home 2.x systems:

wget http://nerdvittles.com/aah2/app_nv_faxdetect.c

Modifying the NVfaxdetect Source Code. Skip this section if you downloaded the source for your version of Asterisk@Home directly from Nerd Vittles. Otherwise, a change needs to be made in the NVfaxdetect source code whether you are running Asterisk@Home 1.5 or Asterisk@Home 2.x. Edit the source code by issuing the following command: nano -w app_nv_faxdetect.c.

If you're using Asterisk@Home 1.5, search for the word CALLERID in the source file: Ctrl-W, CALLERID. When it finds the match, you'll be in the middle of three lines of code that look like this:

// Use the second one for recent Asterisk releases
#define CALLERID_FIELD cid.cid_num
//#define CALLERID_FIELD callerid

Change these three lines so that the first define line is commented out and the second one is uncommented. Your code should look like the following when you're finished:

// Use the second one for recent Asterisk releases
//#define CALLERID_FIELD cid.cid_num
#define CALLERID_FIELD callerid

Once you complete the change, save the file: Ctrl-X, Y, then press Enter.

If you're using Asterisk@Home 2.x, we need to make a different change in the source code. Search for #include with the command: Ctrl-W, #include. When the match is found, move the cursor up one line, press the Enter key, and insert the following code:

  • Ignore the two dots in the right column above. WordPress quirk! Once you make this addition, save the file: Ctrl-X, Y, then press Enter.

    Adjusting Makefile. Regardless of your version of Asterisk@Home, we need to modify Makefile to include this code in the Asterisk executable: nano -w Makefile. With AAH 2.x, search for the word "experimental": Ctrl-W, experimental. Move down one line and press Enter. With AAH 1.5, search for the expression "#APPS+": Ctrl-W,#APPS+. Move up one line and press Enter. Now, with either version, add the following making sure there is no pound sign (#) at the beginning of the line:

    APPS+=app_nv_faxdetect.so

    Once you make this addition, save the file: Ctrl-X, Y, then press Enter.


    Recompiling Asterisk. Now we're ready to recompile and reinstall the Asterisk application with your new NVfaxdetect code. Issue the following commands:

    cd /usr/src/asterisk
    make
    make install

    You'll get some warning messages when the install completes. You can safely ignore them. When the install is finished, you can restart Asterisk and use the Command Line Interface (CLI) to make certain that NVfaxdetect installed properly:

    amportal start
    asterisk -r
    set verbose 10
    show application nvfaxdetect

    The following CLI message should be displayed:

    This application listens for fax tones (on IAX and SIP channels too)
    for waitdur seconds of time. In addition, it can be interrupted by digits,
    or non-silence. Audio is only monitored in the receive direction. If
    digits interrupt, they must be the start of a valid extension unless the
    option is included to ignore. If fax is detected, it will jump to the
    'fax' extension. If a period of non-silence greater than 'mindur' ms,
    yet less than 'maxdur' ms is followed by silence at least 'sildur' ms
    then the app is aborted and processing jumps to the 'talk' extension.
    If all undetected, control will continue at the next priority.
    waitdur: Maximum number of seconds to wait (default=4)
    options:
    'n': Attempt on-hook if unanswered (default=no)
    'x': DTMF digits terminate without extension (default=no)
    'd': Ignore DTMF digit detection (default=no)
    'f': Ignore fax detection (default=no)
    't': Ignore talk detection (default=no)
    sildur: Silence ms after mindur/maxdur before aborting (default=1000)
    mindur: Minimum non-silence ms needed (default=100)
    maxdur: Maximum non-silence ms allowed (default=0/forever)
    Returns -1 on hangup, and 0 on successful completion with no exit conditions.

    For questions or comments, please e-mail support@newmantelecom.com.

    Adjusting Your Dialplans to Implement Fax Detection. The final step in this process is to adjust the Asterisk dialplans to implement fax detection and process incoming faxes. Several different methods are shown below. Choose the one that applies to your deployment of Asterisk.


    For those using a standard Asterisk 1.5 or Asterisk 2.x install with no Stealth AutoAttendant, you'll need to make the following changes to both the [from-pstn-reghours] and [from-pstn-afthours] contexts in the extensions.conf config file.

    To modify [from-pstn-reghours], use the Asterisk Management Portal (AMP) to access AMP->Maintenance->Config Edit->extensions.conf->from-pstn-reghours. Delete all of the existing code:

    exten => s,1,GotoIf($[${FAX_RX} = disabled]?from-pstn-reghours-nofax,s,1:2) ; if fax detection is disabled, then jump to from-pstn-nofax - else continue
    exten => s,2,Answer
    exten => s,3,Wait(1)
    exten => s,4,SetVar(intype=${INCOMING})
    exten => s,5,Cut(intype=intype,-,1)
    exten => s,6,GotoIf($[${intype} = EXT]?7:9) ; If INCOMING starts with EXT, then assume its an extension
    exten => s,7,Wait(3) ;wait 3 more second to make sure this isn't a fax before dialing someone
    exten => s,8,Goto(ext-local,${INCOMING:4},1)
    exten => s,9,GotoIf($[${intype} = GRP]?10:12) ; If INCOMING starts with GRP, then assume its a ring group
    exten => s,10,Wait(3)
    exten => s,11,Goto(ext-group,${INCOMING:4},1)
    exten => s,12,GotoIf($[${intype} = QUE]?13:15)
    exten => s,13,Wait(3)
    exten => s,14,Goto(ext-queues,${INCOMING:4},1)
    exten => s,15,Goto(${INCOMING},s,1) ; not EXT or GR1 - it's an auto attendant
    exten => fax,1,Goto(ext-fax,in_fax,1)
    exten => h,1,Hangup

    Then insert the following new code in the [from-pstn-reghours] context and click the Update button:

    exten => s,1,GotoIf($[${FAX_RX} = disabled]?from-pstn-reghours-nofax,s,1:2); if fax detection is disabled, then jump to from-pstn-nofax - else continue
    exten => s,2,Answer
    exten => s,3,Playtones(ring) ; play fake ring so caller doesn't wonder whats going on
    exten => s,4,NVFaxDetect(10) ; while playing ring sound, detect faxes for 2 rings (goes to "fax" extension if detected)
    exten => s,5,SetVar(intype=${INCOMING})
    exten => s,6,Cut(intype=intype,-,1)
    exten => s,7,GotoIf($[${intype} = EXT]?8:9) ; If INCOMING starts with EXT, then assume its an extension
    exten => s,8,Goto(ext-local,${INCOMING:4},1)
    exten => s,9,GotoIf($[${intype} = GRP]?10:11) ; If INCOMING starts with GRP, then assume its a ring group
    exten => s,10,Goto(ext-group,${INCOMING:4},1)
    exten => s,11,GotoIf($[${intype} = QUE]?13:14)
    exten => s,13,Goto(ext-queues,${INCOMING:4},1)
    exten => s,14,Goto(${INCOMING},s,1) ; not EXT or GRP - it's an auto attendant
    exten => fax,1,Goto(ext-fax,in_fax,1)
    exten => h,1,Hangup

    Now we need to make a similar change in the [from-pstn-afthours] context. Replace the following code:

    exten => s,1,GotoIf($[${FAX_RX} = disabled]?from-pstn-afthours-nofax,s,1:2) ; if fax detection is disabled, then jump to from-pstn-nofax - else continue
    exten => s,2,Answer
    exten => s,3,Wait(1)
    exten => s,4,SetVar(intype=${AFTER_INCOMING})
    exten => s,5,Cut(intype=intype,-,1)
    exten => s,6,GotoIf($[${intype} = EXT]?7:9) ; If INCOMING starts with EXT, then assume its an extension
    exten => s,7,Wait(3) ;wait 3 more second to make sure this isn't a fax before dialing someone
    exten => s,8,Goto(ext-local,${AFTER_INCOMING:4},1)
    exten => s,9,GotoIf($[${intype} = GRP]?10:12) ; If INCOMING starts with GRP, then assume its a ring group
    exten => s,10,Wait(3)
    exten => s,11,Goto(ext-group,${AFTER_INCOMING:4},1)
    exten => s,12,GotoIf($[${intype} = QUE]?13:15)
    exten => s,13,Wait(3)
    exten => s,14,Goto(ext-queues,${AFTER_INCOMING:4},1)
    exten => s,15,Goto(${AFTER_INCOMING},s,1) ; not EXT or GR1 - it's an auto attendant
    exten => fax,1,Goto(ext-fax,in_fax,1)
    exten => h,1,Hangup

    Replace the above code with the following new code and then click the Update button:

    exten => s,1,GotoIf($[${FAX_RX} = disabled]?from-pstn-afthours-nofax,s,1:2); if fax detection is disabled, then jump to from-pstn-nofax - else continue
    exten => s,2,Answer
    exten => s,3,Playtones(ring) ; play fake ring so caller doesn't wonder whats going on
    exten => s,4,NVFaxDetect(10) ; while playing ring sound, detect faxes for 2 rings (goes to "fax" extension if detected)
    exten => s,5,SetVar(intype=${AFTER_INCOMING})
    exten => s,6,Cut(intype=intype,-,1)
    exten => s,7,GotoIf($[${intype} = EXT]?8:9) ; If INCOMING starts with EXT, then assume its an extension
    exten => s,8,Goto(ext-local,${AFTER_INCOMING:4},1)
    exten => s,9,GotoIf($[${intype} = GRP]?10:11) ; If INCOMING starts with GRP, then assume its a ring group
    exten => s,10,Goto(ext-group,${AFTER_INCOMING:4},1)
    exten => s,11,GotoIf($[${intype} = QUE]?13:14)
    exten => s,13,Goto(ext-queues,${AFTER_INCOMING:4},1)
    exten => s,14,Goto(${AFTER_INCOMING},s,1) ; not EXT or GRP - it's an auto attendant
    exten => fax,1,Goto(ext-fax,in_fax,1)
    exten => h,1,Hangup


    For those using the Nerd Vittles' Stealth AutoAttendant to process incoming calls, you'll need to adjust the extension 111 script in your extensions_custom.conf file. Here's the NVfaxdetect setup that we use which also includes the BlackList, CallerID, and Bluetooth Proximity Detection systems we've previously built. So, yes, we do eat our own dog food. Special note: We don't accept faxes on our Southern Bell PSTN line (111,6,Goto(9)). If you'd prefer to accept them, then change Goto(9) to Goto(7).

    exten => 111,1,LookupBlacklist ; If CID blacklisted, goto 102 ; Check for creeps
    exten => 111,2,Answer
    exten => 111,3,GotoIf($["${CALLERIDNUM:0:2}" = "00"]?4:7) ; Special Handling for SPA-3000
    exten => 111,4,SetCIDNum(${CALLERIDNUM:2})
    exten => 111,5,LookupBlacklist ; If CID blacklisted, goto 106 ; Gotta do it again after adjusting CallerID
    exten => 111,6,Goto(9)
    exten => 111,7,Playtones(ring) ; play fake ring so caller doesn't wonder whats going on
    exten => 111,8,NVFaxDetect(10) ; while playing ring sound, detect faxes for seconds (goes to "fax" extension if detected)
    exten => 111,9,SetMusicOnHold(default)
    exten => 111,10,Wait(1)
    exten => 111,11,GotoIf($["${CALLERIDNUM}" = ""]?who-r-u,s,1)
    exten => 111,12,GotoIf($["foo${CALLERIDNUM}" = "foo"]?who-r-u,s,1)
    exten => 111,13,GotoIf($["${CALLERIDNAME:0:9}" = "Anonymous"]?who-r-u,s,1)
    exten => 111,14,GotoIf($["${CALLERIDNAME:0:7}" = "Unknown"]?who-r-u,s,1)
    exten => 111,15,GotoIf($["${CALLERIDNUM:0:7}" = "Private"]?who-r-u,s,1)
    exten => 111,16,GotoIf($["${CALLERIDNAME:0:7}" = "Private"]?who-r-u,s,1)
    exten => 111,17,GotoIf($["${CALLERIDNUM:0:10}" = "Restricted"]?who-r-u,s,1)
    exten => 111,18,GotoIf($["${CALLERIDNAME:0:11}" = "OUT OF AREA"]?who-r-u,s,1)
    exten => 111,19,GotoIf($["${CALLERIDNUM:0:4}" = "PSTN"]?who-r-u,s,1)
    exten => 111,20,GotoIf($["${CALLERIDNUM:0:3}" = "199"]?who-r-u,s,1)
    exten => 111,21,GotoIfTime(${REGTIME}|${REGDAYS}|*|*?25)
    exten => 111,22,Background(silence/2)
    exten => 111,23,VoiceMail(204@default)
    exten => 111,24,Hangup
    exten => 111,25,AGI(calleridname.agi)
    exten => 111,26,Background(custom/welcome)
    exten => 111,27,DigitTimeout,2
    exten => 111,28,ResponseTimeout,2
    exten => 111,102,Goto(custom-blacklisted,s,1)
    exten => 111,106,Goto(custom-blacklisted,s,1)
    exten => fax,1,Goto(ext-fax,in_fax,1)
    exten => t,1,Background(pls-hold-while-try)
    exten => t,2,AGI(homecheck.agi)
    exten => t,3,GotoIf($["${WARD:0:2}" = "OU"]?custom-outhouse,s,1:4)
    exten => t,4,Dial(local/222@from-internal,20,m)
    exten => t,5,VoiceMail(204@default)
    exten => t,6,Hangup
    exten => t,105,Voicemail(204@default)
    exten => t,106,Hangup
    exten => i,1,Playback(wrong-try-again-smarty)
    exten => i,2,Goto(111,26)
    exten => o,1,Macro(rg-group,20,,200-201-204-210)
    exten => o,2,VoiceMail(204@default)
    exten => o,3,Hangup
    exten => h,1,Hangup

    After you finish up the remainder of this tutorial and try a test fax, you may need to adjust the number in the NVfaxdetect lines (s,4 or 111,8) of the above contexts. The original tutorial we read on this topic had 4 for the value which was supposed to mean 4 seconds; however, Asterisk read it as 4 milliseconds. 10 works on both of our Asterisk systems, one version 1.5 and one version 2.2. YMMV. Others have had luck deleting the number altogether leaving just the open and closed parentheses. Try different approaches until it works reliably on your system. What you're striving for is just enough time to detect a fax without putting regular callers to sleep waiting on your fax detection mechanism to complete its task.


    Whether you're using a standard Asterisk@Home 1.5 or 2.x or the Stealth AutoAttendant, you'll also need to modify the incoming fax context. Just choose the code below that matches your version of Asterisk and replace the existing content in [ext-fax]: AMP->Maintenance->Config Edit->extensions.conf->ext-fax. Don't forget to restart Asterisk after making these changes. From a command prompt while logged in as root, the following command will do it in Asterisk@Home 2.2: amportal restart. For Asterisk@Home 1.5 users, it takes two commands: amportal stop then amportal start. Then you'll be ready to start receiving junk faxes just like we do. Enjoy!

    For Asterisk@Home 1.5 systems whether you're using the Stealth AutoAttendant or not, replace the existing contents of [ext-fax] with the following code. If you cut-and-paste, be sure to replace the typographic quote marks in line h,2 with regular quotation marks or expect smoke.

    exten => s,1,Answer
    exten => s,2,Goto(in_fax,1)
    exten => in_fax,1,StopPlaytones ; you must do this or it will play ring sounds over your fax
    exten => in_fax,2,GotoIf($[${FAX_RX} = system]?3:analog_fax,1)
    exten => in_fax,3,Macro(faxreceive)
    exten => in_fax,7,Hangup
    exten => analog_fax,1,GotoIf($[${FAX_RX} = disabled]?3:2) ;if fax is disabled, just hang up
    exten => analog_fax,2,Dial(${FAX_RX},20,d)
    exten => analog_fax,3,Hangup
    exten => out_fax,1,txfax(${TXFAX_NAME}|caller)
    exten => out_fax,2,Hangup
    exten => h,1,system(tiff2ps -2eaz -w 8.5 -h 11 ${FAXFILE} | ps2pdf - ${FAXFILE}.pdf)
    exten => h,2,system(mime-construct --to ${EMAILADDR} --subject "Fax from ${CALLERIDNUM} ${CALLERIDNAME}" --attachment ${CALLERIDNUM}.pdf --type application/pdf --file ${FAXFILE}.pdf)
    exten => h,3,system(rm ${FAXFILE} ${FAXFILE}.pdf)
    exten => h,4,Hangup()

    For Asterisk@Home 2.x systems whether you're using the Stealth AutoAttendant or not, replace the existing contents of [ext-fax] with the following code. If you cut-and-paste, be sure to replace the typographic quote marks in line h,2 with regular quotation marks or expect smoke.

    exten => s,1,Answer
    exten => s,2,Goto(in_fax,1)
    exten => in_fax,1,StopPlaytones ; you must do this or it will play ring sounds over your fax
    exten => in_fax,2,GotoIf($[${FAX_RX} = system]?3:analog_fax,1)
    exten => in_fax,3,Macro(faxreceive)
    exten => in_fax,7,Hangup
    exten => analog_fax,1,GotoIf($[${FAX_RX} = disabled]?3:2) ;if fax is disabled, just hang up
    exten => analog_fax,2,DBGet(DIAL=DEVICE/${FAX_RX}/dial);
    exten => analog_fax,3,Dial(${DIAL},20,d)
    exten => analog_fax,4,Hangup
    exten => out_fax,1,txfax(${TXFAX_NAME}|caller)
    exten => out_fax,2,Hangup
    exten => h,1,system(tiff2ps -2eaz ${FAXFILE} | ps2pdf - ${FAXFILE}.pdf)
    exten => h,2,system(mime-construct --to ${EMAILADDR} --subject "Fax from ${CALLERIDNUM} ${CALLERIDNAME}" --attachment ${CALLERIDNUM}.pdf --type application/pdf --file ${FAXFILE}.pdf)
    exten => h,3,system(rm ${FAXFILE} ${FAXFILE}.pdf)
    exten => h,4,Hangup()

    R.I.P. WordPress Cut-And-Paste Nightmare. For long-time readers of this column, you know what a royal pain cutting-and-pasting has been at Nerd Vittles thanks to the WordPress blog's proclivity for changing quotation marks (used in many Asterisk commands) to 'smart quotes'. The original version of this column introduced an entirely new problem when WordPress replaced double-hyphens (used in many Linux commands) with 'long hyphens.' The end result of these quirks has been that, while the code worked great on our development systems, it blew up when you used cut-and-paste to move it to your Asterisk server. This all came to a head this past week when this article on faxing hit the street and blew up on every reader's system because of the double-hyphens (h,2 above), a problem that neither we nor anyone else in the WordPress blog community had ever documented.

    Just like everything else that's great about the Open Source community, there is always someone smart enough not only to recognize a problem but also to fix it. So our hat is forever tipped to Alex King, one of WordPress's most ardent supporters. He wrote about the smart quotes problem and then he single-handedly fixed it with his WP Unformatted Plugin. As luck would have it, the plugin also resolves the double-hyphen problem. It just took us a while to discover the plugin. But there's nothing like an extra scoop of egg on your face to make you scratch a little harder for a solution. We were either going to solve the formatting problems or give WordPress the heave-ho. Now that we've implemented the plugin, we'll be using it regularly and, as quickly as we can, we'll go back and rework all of our previous articles just as we have this one. Hopefully the problem is history both for you and for us. Should you see any Nerd Vittles code that still looks like it has quotation marks pointing in two different directions, please let us know. And ... our apologies for the mess.


    Some Recent Nerd Vittles Articles of Interest...


    39 Comments

    1. First off, thanks for your guide, it’s been a great help. Second, I’m not sure if it’s just me, but I can’t connect to newmantelecom.com to download NVFaxdetect. Is there any way you could throw up a copy to download?

      [WM: We just had a problem downloading the source as well so you now can get it directly from Nerd Vittles. See the amended article above for the appropriate wget commands to obtain the patched source for your particular version of AAH.]

    2. Thanks for all your tutorials – Your fax article is especially timely. Do you know of a good open source solution for sending faxes?
      We currently use CallXpress and RightFax, and it looks like most (if not more) of what I get from those products can be done with Asterisk.

    3. I installed install-pdf., I set fax and email settings in AMP I issued the comand
      wget http://nerdvittles.com/aah2/app_nv_faxdetect.c

      When I try to adjust Makefile I can not find the word experimental in the file. Where is this file located so I can edit it with winscp374?

      [WM: Ooops. You’re right. Asterisk@Home 1.5 doesn’t have it. Sorry! I’ve corrected the article. With AAH 1.5, open Makefile: nano -w /usr/src/asterisk/apps/Makefile. Search for the expression "#APPS+": Ctrl-W,#APPS+. Move up one line and press Enter. Now add the following making sure there is no pound sign (#) at the beginning of the line:

      APPS+=app_nv_faxdetect.so

      Once you make this addition, save the file: Ctrl-X, Y, then press Enter.]

    4. Ward, Thank you so much for this great utility and instructions. I have this working however; it is not emailing me the fax. I recieve email’s from every voicemail, but just not the faxes. Does anything need to be set in the inbound routing DID. I have it set to AMP default. Is there anyway to check why I am not receiving the email’s? When I check via command line, I see the fax being generated and converted to a pdf and it shows sending to my email address, I just don’t ever receive it.

      [WM: Use WebMin to check the mailboxes under SendMail and see where they’re going. Then report back.]

    5. I am having same issue. /var/log/maillog does not show ANY emails being sent for faxes… voicemail ones go out fine. I retyped the h,2 line in [ext-fax] because it was causing malformed command after I "fixed" the quote marks in it afte cut and paste – that allowed the files to be created in the spool directory, but they are still not being sent. Oh, I also had to reboot Asterisk not just restart it in order for nvfaxdetect to show up as registered. Thanks for all of your great tips, and may I just say "Telasip ROCKS!"

      [WM: A few folks are having the same problem. Keep an eye on this Voxilla forum thread as we troubleshoot and hopefully resolve the problem for everyone. It’s difficult to do this through blog comments.

      Update: Here are three fixes that seem to work:

      1. Change the following line in [ext-fax]:

      exten => h,1,system(tiff2ps -2eaz -w 8.5 -h 11 ${FAXFILE} | ps2pdf – ${FAXFILE}.pdf)

      to this:

      exten => h,1,system(tiff2ps -2eaz ${FAXFILE} | ps2pdf – ${FAXFILE}.pdf)

      2. Be sure you also replace the typographic quotation marks with regular quote marks in exten=>h,2. Damn that WordPress!

      3. In exten=>h,2., replace the displayed single hyphens before the word to, subject, attachment, type, and file (there are five of them) with double-hyphens. Don’t just add another hyphen as the existing long hyphen marks aren’t really hyphen characters at all. Double-damn that WordPress!

      Items 2 and 3 apply regardless of the version of Asterisk being used. Item 1 is only necessary with AAH 2.x systems. Our apologies!]

    6. After several tries I got everything working. I did not have my DID going to my incoming settings but directly to an extension. Once I changed it worked great. How can I have 2 DID receive faxes so they would be emailed to different people? Can it be done if the DID goes to an extension directly?

      GREAT JOB

      Jeff

    7. I followed your directions exactly. I’m running 2.2. I keep getting an error during make and make install that prevents the complete compile. I get "no rule to make app_nv_faxdetect.so…&quot. If I don’t use the new app, everything complies normally. What am I doing wrong?

      [WM: Make sure you’re in the correct directory before you issue the make command.]

    8. Ward — I’ve been using the Newman faxdetect and the built-in fax receive for a while, but have found that some fax senders will not successfully negotiate with Asterisk. My workaround has been to route the inbound fax calls through an FXS to a Windows box with a faxmodem.

      Have you seen any compatibility problems with the Asterisk fax? Unfortunately I don’t have any details on the sender systems that fail.

      [WM: Once in a while, it takes a couple tries. But, other than that, we haven’t seen a problem.]

    9. Is there any way to set it up to fax via a did? I have a couple users that just want to use thier incoming dids as thier fax numbers as well. any help would be appriciated

    10. I’m using sipura 3000 with incoming lines: extension (99) is to handle incoming PSTN calls + exten => 99,4,Goto(aa_1,s,1). Will the configuration above (in this turorial) manage the incoming Fax?
      Thanks a lot.

    11. I followed the instructions above and everything went through as planned. However, when I try to send a fax to my asterisk it gives me Communication error 2001, poor line quality. My asterisk server is connected through a regular PSTN phone line through a x100 generic card.

      [WM: Clone cards are all over the map in quality. Can’t help much on that one … other than get a new card or switch to a VoIP provider. TelaSIP rocks. We use ’em.]

    12. Ward, great tutorial (as always). I have an additional question: can you comment on routing an incoming fax to a printer on my network instead of sending it via email?

    13. I am having an issue with the attachments. They are sent but the attachment name is the entire path described in the variable FAXFILE. So the file is named _var_spool_asterisk_fax_1136517361.5.tif.pdf. This is what I find in the header of the message.

      Content-Disposition: inline; filename=testfax.pdf
      Content-Type: application/pdf;
      name="/var/spool/asterisk/fax/1136517361.5.tif.pdf"

      Is this normal behaviour or is something missing? seems like the slashes are replaced with underscores instead of the attachment being called testfax.pdf like the header would suggest.

      [WM: Normal. It works.]

    14. I followed the instructions above and everything seemed to go well, when sending a fax in the fax connects to the Asterisk system but sits saying connected.

      After a short period it fails to send the fax, Asterisk still then emails me a pdf for the fax but pdf has no pages.

      My fax also prints out a failed report giving me Error 388 (communication error occurred).

      Any ideas?

      [WM: Sounds like a poor connection. Who’s the provider? TelaSIP and AxVoice lines both work. It’s hit and miss with others. And almost always miss with some … such as BV. It also could be lack of a timing source depending upon the trunk that’s being used to take the calls. See this link for how to solve it.]

    15. Hi,

      Were in the UK, we’re currently only testing so got an IAX line from Gradwell.com to test – the voice side is all fine.

      This is the point I beleive it goes wrong at from looking at the log (just guessing):

      Jan 12 13:07:03 VERBOSE[4788] logger.c: — Executing RxFAX("IAX2/gradwell-out-1″, "/var/spool/asterisk/fax/1137071218.48.tif") in new stack
      Jan 12 13:07:03 NOTICE[4788] channel.c: Dropping incompatible voice frame on IAX2/gradwell-out-1 of format slin since our native format has changed to ulaw

    16. i seem to have to same problem as above:

      Jan 20 07:49:42 VERBOSE[3575] logger.c: — Executing RxFAX("SIP/anonymous.invalid-08ea98e0″, "/var/spool/asterisk/fax/1137714579.5.tif") in new stack
      Jan 20 07:49:42 NOTICE[3575] channel.c: Dropping incompatible voice frame on SIP/anonymous.invalid-08ea98e0 of format slin since our native format has changed to ulaw

      any ideas?

      [WM: Either your transmission protocol isn’t set to ulaw or your provider’s network isn’t configured to support faxing.]

    17. I am curious about this, doesn AAH have SPANDSP which is supposed to already provide Fax support?
      I know that when you use Asterisk@home 2.2 under inbound routing there is the ability to enable fax detection for that DID by selecting "AMP Default", "disbaled", "system" or you can choose any user extension you need.

      So does this mean that the built in support for AAH 2.2 doesnt work?

      I am just trying to have an adapter which is connected to a fax machine be able to pick up and receieve faxes.

      [WM: You need a Digium board for SpanDSP to work.]

    18. I need help! I get a lot of legal size paper faxes. When I open them, they are cut to normal size(8 1/2 by 11). How can I fix this problem? The other thing, would you please teach how to send faxes!

    19. Hi Ward, no words about your tutorials, simply excellent and usefull.
      My question is, what about sending faxes? I mean the same way, with no fax machine or hardware requirement. I’m thinking about email to fax. I know about two apps that should do something like this, astfax and asterfax. Ever tried them? Alternative you can suggest?
      Thanks a lot!

    20. Help I have tried everything but I never get the fax tones Asterisk 2.5 with the Digum Card 8 FXS 4 FXO with Echo cancellation. I am willing to pay for help if anyone can help me the asterisk is working but I can not get the fax working. Thank you.

      [WM: Your issue has been reported. Keep an eye on this link for updates. In the meantime, I would try reinstalling from scratch using our tutorial and see what happens.]

    21. Ward,

      Followed your instructions for getting incoming faxes to be handled by AAH. I’m using an auto attendant for my incoming SIP trunk from Axvoice and have set up the fax handling in the aa_1 context which I created using AMP. To do this, I only had to add the following lines to the aa_1 context in extensions_additional.conf using phpconfig.php page in AMP as the fax extension line ( exten => fax,1,Goto(ext-fax,in_fax,1) ) is already in the aa_1 context

      exten => s,4,Playtones(ring) ; play fake ring so caller doesn’t wonder whats going on
      exten => s,5,NVFaxDetect(10) ; while playing ring sound, detect faxes for 2 rings (goes to "fax" extension if detected)

      Receiving incoming faxes and the resulting e-mails with pdf file attached is working fine. However, I am having a problem which I think is related to AMP. Whenever, I create a new extension in AMP, or make any other change which requires the extensions_additional.conf file to be written to, the above additions which I have made to aa_1 context in extensions_additional.conf are removed. It appears that the aa_1 context is being overwritten by AMP. Are you aware of any bug in AMP which might be causing this or is this normal? I would expect that any changes which I make to a config file should not be arbitrarily removed.

      Thanks,
      Dave

      [WM: AMP rewrites extensions_additional.conf every time you save any additions using AMP. If you need to protect stuff, put it in extensions_custom.conf which does not get tampered with by AMP.]

    22. [WM: You need a Digium board for SpanDSP to work.]

      This is a nice site but there is also some wrong information unfortunatly. SpanDSP does NOT require a digium board to work, this is wrong. I notice that any questions about sending faxes are being ignored, so, Asterfax is is the best solution right now & works with AAH – although you should know that sending and reciving faxes via VoIP is hit and miss, this is what T.37 & T.38 is for (FoIP). VoIP has issues with frames slips which are not noticable with Voice calls but can really screw up faxes.

      [WM: You’re absolutely right. There is some wrong information on our site. Never claimed to be anything but human. But when smart folks come along and correct us, we’ll be the first to publish our mistakes for all the world to read. As for SpanDSP, I read an awful lot, and I can’t recall anyone ever mentioning that they got SpanDSP to work reliably without a Digium board but, as you say, VoIP has other issues with faxes. We use NVfaxdetect with TelaSIP IP connections, and it works reliably for us 95% of the time. And we’re batting 100% with junk faxes. That’s good enough for us (Ma Bell wasn’t any better!) but, as they say, YMMV.]

    23. Well I am part way there.. I followed this documentation on a AAH 2.3 system (upgraded to 2.5 via an update script) and I was found that my * system was not sending fax tones when faxes were received. I sent Ward an email and he directed me to post on Voxilla and other forums. I did post on forums however no one responded.

      So.. I did some digging and came upon information that kinda clicked. In the code "Macro(faxreceive)" it calls rxfax. At the CLI I did a "show applications" and found that rxfax was not listed.

      So.. Down that road I went and ended up downloading the source for spandps. I compiled it and it created the rxfax.c and o files. I followed all directions to rebuild Asterisk. It created the app_rxfax.so file. I rebooted and wham bam.. I now have this app listed in the CLI and my system now sends fax tones and syncs with a fax machine.

      My issue now is that I am receiving "poor line condition" issues on the remote fax machines. I do not know where to go from here. I have checked to make sure ztdummy is loaded for timing and I removed the "allow=alaw" command from the sip.conf to force ulaw (I read somewhere to do so).

      I am running Telasip as my Voip provider. I will keep trudging and looking around. Any suggestions are greatly appreciated.

      [WM: Not sure where you found the update script that was used to move from 2.3 to 2.5, but it really doesn’t matter. I’m pretty sure it probably (permanently) broke reliable faxing. The whole faxing technology was changed in version 2.4 and remains in 2.5 if my memory serves me correctly. Therefore, doing an in place upgrade probably broke something. That’s a very good reason why we always recommend doing screen captures of AMP data and then a fresh ISO install.]

    24. Installed Fax, as Ward told us in his wonderfoul tutorial.
      At the end of transmission I have an epty .tif file.

      from sip.conf, I defined alaw & ulaw & gsm codec, so it’s not a codec problem. The problem is also found calling extension 666, so the problem not depends on the VOIP provider.
      Any suggestion? Thanks

      [WM: If this is AAH 2.5, there apparently are some issues. Check the SourceForge and Voxilla forums for details.]

    25. When I say update script..

      It was the down and dirty script to update 2.3 to 2.4 that was either part of your Soup to Nust write-up when A@H did the overnight version 2.3->2.4->2.5 update. The script updated Asterisk from 1.2.2 to 1.2.3. I later modified it to update Asterisk to 1.2.4.

      I will reinstall. Thanks for the information.

    26. Forgot to mention I also think the tiff is blank. When monitorinsk asterisk, it appears everything is perfect. However – from the senders end the fax never completes 100% – it appears to but then says "send error". Line noise is not the problem – I can plug in a real fax machine and it works fine. BTW, awesome site – I would have never got this far without it.

      [WM: My non-scientific answer is that some fax machines work great with this, and others have real problems communicating. I’ll keep scratching, but if you need 100% reliability, IP faxing just isn’t quite soup yet.]

    27. "IP faxing just isn?¢ÀÜ?°?Ǭ¢?¢‚Ǩ?°?ɂİ?Ǭ®?¢‚Ǩ?°?É‚Äò?Ǭ¢t quite soup yet"

      Im using an X100P. Same card in a windows machine will send/rec faxes no problem. Somehow, I think this is some kind of configuration problem, just cant put my finger on it. IM changing the script to not delete the files after emailing, that way I can get a closer look at what is happening. Ill let you know if I find anything interesting.

    28. OK- It appears worse than I thought. The tiff file is NEVER created. Individually, I removed the command to delete the files after creation, removed tiff2ps, and removed ps2pdf – and tried combination of removals. The tiff is never in the directory. I also tried redefining the saved directory to /home/fax and nada.

      Anyone have any thoughts on this? In the call llog asterisk does recognize the call as a fax call.

      I’m stumped.

      [WM: If Asterisk doesn’t recognize it as a fax call, then experiment with changing the time parameter in the NVfaxdetect command. We have found that some fax machines work almost every time. Others rarely can connect. No idea why. We tell people to listen for the AutoAttendant and, if they hear it kick in, hang up and try the fax call again. 8 out of 10 times with most fax machines, that solves it at least using a TelaSIP IP trunk.]

    29. Any ideas why * would recognizeit as a fax call but not create any tiff file?

      [WM: Be sure you got rid of the 8.5 x 11 dimensions in the tiff conversion routine.]

    30. I’ve been testing FAX to Email with ASterisk@home2.7 and TE110P and after all of your instructions i couldn’t open PDF file with My Outlook.

      I’ve been reading in the web and i found this:
      http://www.voip-info.org/wiki/view/Asterisk+and+faxes

      Update ?¢‚Ǩ‚Äù If the above changes do not fix your mime-construct file, verify the version by going to the unix cli (use keyboard or PuTTY) and type "mime-construct –version". I found that even if I updated the script above, It made it to where the attachment wouldn’t come through at all. I checked my version and I had v1.8. I searched and found that there was a slightly newer version 1.9, so I tried it and it seemed to solve my problems.

      Procedure:
      1. Goto /usr/bin/
      2. Rename "mime-construct" to "mime-construct.old"
      3. Copy the 1.9 code from http://search.cpan.org/src/ROSCH/mime-construct-1.9/mime-construct
      4. Re-create mime-construct and paste the code. Be sure not to get the comments at the bottom, stop before _END_
      5. "chmod 555 mime-construct"

      And In fact i finally got Fax to Email working just Perfect.
      By the Way i’ve change the name of file attachment for ${TIMESTAMP} to avoid files with empty name (sometimes who sends you faxes doesn’t provide caller ID)

      I hope this helps!

      Marco Mouta

    31. 14th March 2006 AsterFax version 1.0 beta 8 released
      After much ado and just plain hard work beta 8 is finally released.
      This released was primarily aimed at improving error handling. Previous released of AsterFax where unable to retrieve transmission errors and as such had to assumed that all transmissions failed. With a patch to txfax we can now get acurate error messages and report them when a transmission fails.
      A lot of clean up work has also been undertaken as well as support for Rich Text Files and landscape mode.
      There is still somework to be done on making the errors human readable.

      Beta 8 is another major milestone in AsterFax’s development. All significant features slated for the version 1.0 release have now been implemented. The remaining working centres around improving the installation process, adding additional converters and adding a header to the fax.

    32. This works great! I do have one issue. How do you set A@H so that it will immediately answer and play fax tones? Basically, I need to set up a dedicated fax extension, but if someone is at a fax and dials with the handset and wait to hear a tone, A@H will think it is a regular call. Any thoughts?

    33. I too am getting the message
      Dropping incompatible voice frame on SIP/gw02.uk.sipgate.net-081938b0 of format slin since our native format has changed to alaw
      I am not sure what this means.As I understand it sipgate.net use equipment that transmits FAXdata. What is one supposed to do about this?

    34. Newbie here! Trixbox 2. Everything looks good, recieving faxes, but tif file includes only part of the real fax pages. Header and first part of tex is ok, then it just cuts it. Filesize vary. Cant find any parameters wich may innfluence this. Any ideas? Or is it just not "quite soup yet" ?

    Comments are closed.