Asterisk 13,xx Fax configuration

Im using ubuntu OS and asterisk 13,15. I need configure FAX to email but from what i found out for asterisk 13+ you need to install Spandsp for being able to Sent and receive faces and sent them to mail. Im loocking for an example configuration but cant find anything. Can you please provide some help?

I have a dialplan as well as a pearl script for fax with spandsp. I’ve been using it in a production system for years.
We have pretty good results.Are you using pjsip?

Yes. Im new in asterisk so im going with the latest versions.did you prepare the script or is it something that already exists?

I have used a perl script that I have modified to fit my needs:
You will also need tiff2pdf.
My script:

use MIME::Lite;
my ($filename,$person,$email,$fromcallerid,$departement) = @ARGV;
my $msg = MIME::Lite->new(From => '',To => $email,Subject => "Fax received!",Type => 'multipart/mixed');
$msg->attach(Type => 'TEXT',Data => "Dear $person,\n\n\tYou have a new fax from: $fromcallerid. " ."See attached file.\n\nMy company FAX\n");
#Send email
$msg->attach(Type => 'application/pdf',Path => "/var/spool/asterisk/fax/pdf/$departement/$filename.pdf",Filename => "fax-$filename.pdf",Disposition => 'attachment');

;Fax from pstn
exten => 6847638,1,Gosub(Sub_Fax_Reception,start,1(Joe Black,${GET_Email_FAX_Destination(${EXTEN})},Sales))

exten => 6669696,1,Gosub(Sub_Fax_Reception,start,1(Bruce Dickinsons,${GET_Email_FAX_Destination(${EXTEN})},Sales))

;Subroutine for fax reception

exten => start,1,NoOp()
same => n,Answer()
;Check if the fax number is in the blacklisted database
same => n,Set(Bad_CID=${READ_Blacklist(Caller_ID,${CALLERID(num)})})
same => n,GotoIf($["${Bad_CID}"  > "1"]?SPAM_Number:Valid_Number)

same => n(Valid_Number),Set(destination=${ARG1})
same => n,Set(Email_destination=${ARG2})
same => n,Set(Departement_destination=${ARG3})
;Folder where the fax are received
same => n,Set(FAXDEST=/var/spool/asterisk/fax)
same => n,Set(tempfax=${STRFTIME(,,%C%y%m%d%H%M)}-${Departement_destination})
;Hangup handler
same => n,Set(CHANNEL(hangup_handler_push)=hdlr_Process_Fax,s,1(args))
same => n,ReceiveFAX(${FAXDEST}/${tempfax}.tif,fd)
same => n,Hangup()

;Blacklisted fax
same  => n(SPAM_Number),NoOp()
same  => n,Zapateller(answer)
same  => n,Hangup()

;Send fax by email after it has been received

exten => s,1,NoOp()
;Log fax status in database
same => n,Set(WRITE_FAX-ENTRANT()='${CALLERID(All)}','${Email_Destinataire}','${FAXBITRATE}','${FAXPAGES}','${FAXERROR}','${FAXSTATUS}')
;Validate if FAX is successful
;Convert tiff file to PDF
same => n(FAX_SUCCESS),NoOp()
same => n,System(/usr/bin/tiff2pdf /var/spool/asterisk/fax/${tempfax}.tif  >  /var/spool/asterisk/fax/pdf/${Departement_Destinataire}/${tempfax}.pdf)
;Send PDF fax to email with Perl
same => n,System(/var/lib/asterisk/agi-bin/ ${tempfax} "${Destinataire}" ${Email_Destinataire} "${CALLERID(num)}" ${Departement_Destinataire})
same => n(FAX_FAILED),NoOp()
same => n,Return()
1 Like

so the only thing needed to be done is to create the script and modify the extensions.conf file?
isnt there a need to create endpoint in the pjsip.conf file?

Yes, you do need an endpoint in pjsip.conf.
We are using a Mediatrix 3632 as a ISDN to SIP gateway.
Here’s how my pjsip.conf file look like:

type = aor
contact = sip:

type = identify
endpoint = PRITrunk
match =

type = auth
username = my_username
password = my_password

type = endpoint
context = FROM_PRI
dtmf_mode = info
disallow = all
allow = ulaw
ice_support = no
direct_media = no
tos_audio = 0xB8
cos_audio = 6
auth = PRITrunk
fax_detect = yes
t38_udptl = yes
t38_udptl_maxdatagram = 400
outbound_auth = PRITrunk
aors = PRITrunk
language = fr
tone_zone = us

Thanks a lot for the help!
Im now able to receive fax but i cant sent. Do i need any additional services for that? or just dial plan in extensions.conf?

I’ve struggled a long time to get a good success rate for sending a fax. I now use some SPA8000 ATA connected to physical fax machines.Asterisk act as a T38 gateway and then dial out via our PRI. The success rate is over 90% at 14400.

Regular FAX machine ----> SPA8000 ----> Asterisk -----> PRI


exten => _NXXNXXXXXX,1,NoOp(Outgoing fax from SPA8000)
same  => n,Set(Unique_Fax_ID=${RAND()}_${STRFTIME(,,%C%y%m%d%H%M)})
same  => n,Set(WRITE_FAX-ATA-OUT()='${Unique_Fax_ID}','${GET_EXT_CID(${CHANNEL(endpoint)})}','${CALLERID(number)}','${EXTEN}')

;Hangup handler to get fax status after  hangup
same  => n,Set(CHANNEL(hangup_handler_push)=hdlr_Outgoing_Fax,s,1(args))
;T38 gateway
same  => n,Set(FAXOPT(gateway)=yes)
same  => n,Dial(PJSIP/${EXTEN}@${PRI_SORTANT},60)
same  => n,Hangup()

exten => s,1,NoOp(Outgoing fax From ATA)
;Write fax status to our DB
same  => n,Set(SET_FAX_SORTANT_STATUS()=${DIALSTATUS},${CDR(billsec)},${Unique_Fax_ID})
same  => n,Return()

Here’s my audio settings in my SPA8000:

1 Like

Ive used a little bit different method. I used IAX connected to hylafax
Here are the manuals: