Using Asterisk to Detect and Redirect Fax Calls for Communications Server

Microsoft Office Communications Server 2007 and Microsoft Office Communications Server 2007 R2 will reach end of support on January 9, 2018. To stay supported, you will need to upgrade. For more information, see Resources to help you upgrade your Office 2007 servers and clients.

This article describes how to use Asterisk to monitor incoming (or outgoing) calls for fax tones (traditional fax tones, not T.38), and then react to those tones. Using Asterisk this way enables users to use their phone number as their personal fax number. This is a useful feature, especially if you have some form of automated fax server (or fax to e-mail server). It is intended for configurations where incoming calls pass through Asterisk before reaching Microsoft Office Communications Server, (essentially using Asterisk as a gateway).

Author: Paul Adams

Publication date: June 2010

Product version: Microsoft Office Communications Server 2007 R2, Asterisk 1.6

During a Communications Server 2007 R2 implementation, I used Asterisk 1.6 as a gateway for Communications Server to the outside world. This means that all incoming calls passed through Asterisk before reaching Communications Server.

I’d read that Asterisk could detect incoming fax tones (regular fax tones, not T.38) and redirect the call. I thought that if I could use Asterisk to detect the fax tones, I could then pass the call to a fax machine or fax server. When implementing this, I discovered that you can also pass extra information (in the form of DTMF tones) to indicate who the fax is intended for.

In my network, my users were already using a fax server (Hylafax, a Linux based fax solution). It sends and receives faxes by using four modems. When the fax server receives a fax, it converts the fax to a PDF, and then sends it as an attachment in an e-mail. The address the fax is sent to is based on which modem it arrived in on. For example, a fax arrives on line 1, and is then sent to, or a fax arrives on line 2, and is then sent to I configured modem 4 to send faxes out, and that left three modems for incoming fax lines, and, therefore, a three fax number limit.

Asterisk can pass dual-tone multifrequency (DTMF) codes out to fax machines or other devices. I learned that some fax machines or fax servers can process faxes by using the “extra” DTMF digits sent to them. I also learned that most modern large-scale photocopier, printer, and fax devices can be programmed in this way. In addition, a large number of those devices can receive a fax, convert it to a picture file or PDF, attach it to an e-mail, and send it (and many devices come with free desktop fax sending software).

The point being that you may not need to invest in a separate fax server to get the benefits from this solution. You can even just redirect to a regular fax machine and that still allows your users to use their direct number as their fax number.

In this article, I explain how to configure Asterisk to detect fax tones, and then pass some sort of identification to the fax server so the fax can be routed correctly. I have assumed that the reader has some experience with Linux and Asterisk administration.

Tools You Might Need

You will require access to the command prompt on the Linux server that is running Asterisk. If you are working from your Windows computer and connecting to the Asterisk server, I suggest the excellent free terminal program PuTTY.

You will also have to add NVFaxDetect to your Asterisk installation.


You will need to use the patched version of NVFaxDetect located at the bottom of the page.

Detecting Fax Tones

To configure Asterisk to detect fax tones, do the following:

  1. Install NVFaxDetect on your Asterisk server according to the instructions on the site from which you downloaded it.

  2. On your Asterisk server, navigate to your Asterisk configuration files. (For example, mine are located in /etc/asterisk.)


    Before you edit your Asterisk dial plan, keep in mind that when Asterisk (using NVFaxDetect) detects a fax, it redirects the call to a “fax” extension in the dial plan. If no fax tones are detected, the call then continues to the next step in the dial plan for that number.

  3. Edit the extensions.conf file. (I use the Linux editor vi.)

  4. In this example, let’s assume we receive a four-digit Direct Inward Dialing (DID) call from our voice communications provider (yours maybe more than four). Let’s create a dial plan to detect incoming faxes for the extension 4000. After the [general] and [globals] sections of the extensions.conf file, we will add some rules to deal with the 4000 extension.

    The following table lists each rule and its explanation.

    Rule Explanation

    exten => 4000,1,Answer;

    To detect a fax, first you need to answer the call.

    exten => 4000,n,Ringing;

    The ringing statement plays a ringing tone. If the call is a regular call, not a fax, they will hear ringing tones.

    exten => 4000,n,NVFaxDetect(5);

    Use NVFaxDetect to detect fax tones for up to 5 seconds.

    exten => 4000,n,Dial(sip/to-ocs/+${EXTEN});

    If no fax tones are detected, the next line dials Communications Server and passes the call to the extension (which in this case is 4000).


    In this example, the name used in the dial command (to-ocs) has been defined in the sip.conf file prior to being used in the dial plan. For more details about how to define the name in the sip.conf file, see Geoff Clark’s blog on linking Asterisk and Communications Server at Here’s a hint: it’s the same as Geoff’s SIP_TRUNK entry, just using the name ‘to-ocs’ instead.

  5. We now need to define our fax extension and what to do with our faxes.


    In an Asterisk dial plan, the ‘Dial’ command places calls from Asterisk. The exact details of your dial command may differ from mine depending on your Asterisk setup. My example uses a T1 connection, with the first 4 channels linking directly to my four modem devices.

    Further down in the extensions.conf file, add the following lines (an explanation of what is happening follows the code):

    exten => fax,1,Dial(dahdi/1/${CALLERID(dnid)})
    exten => fax,n,Dial(dahdi/2/${CALLERID(dnid)})
    exten => fax,n,Dial(dahdi/3/${CALLERID(dnid)})
    exten => fax,n,Dial(dahdi/4/${CALLERID(dnid)})
    exten => fax,n,Busy

    Remember I said my fax server had four modems, (1 to send and 3 to receive). I can now use all four modems to pass the incoming faxes to because the routing of the faxes received by the fax server is now based on the numbers passed to the fax server NOT on the line or modem the fax is received on.

    In the previous code, we attempt to pass the incoming fax call to each of the four modems in turn. If the first line is busy, it moves to the second line, then the third, and so on. If one modem is busy sending a fax or receiving a fax from another call, the dial plan moves to the next modem.

    If all four lines are busy, it reaches the ‘Busy’ command that plays a busy signal to the incoming fax call.

    The parameter ‘${CALLERID(dnid)}’ passes the DID number that was called to the fax server (in this example, 4000). You can then program your fax server to send calls for 4000 to the correct destination.

  6. Save and close the extensions.conf file. You will need to reload the dial plan in Asterisk.


Using Asterisk to detect incoming faxes, I was able to offer any user who had a direct DID number the option of a “personal fax line” that delivered their faxes directly to their inbox.

Also, because the destination DID number is passed to the fax server, you can have a ratio of more than one connection to the fax server equals one fax number. For example, you could have sixteen people with direct DID numbers, but only four lines to your fax server.

Additional Information

To learn more, check out the following articles:

Communications Server Resources

We Want to Hear from You