Tag Archives: dynamic

Receiving faxes with Asterisk, iaxmodem and HylaFax with dynamic eMail recipients

This is still the best how-to for sending and receiving faxes with Asterisk 1.4 without T.38: http://das-asterisk-buch.de/1.6/faxserver-mit-iaxmodem-und-hylafax.html – in German only, but you can probably still figure it out. I use this setup only to receive faxes and have them mailed as PDFs to the recipient. The speciality here is that the eMail address of the recipient is defined based on the called number, dynamically.

This is extensions.conf:

[fax-incoming]
exten => +496980001234,1,Dial(IAX2/iaxmodem/+496980001234)
exten => +442055446677,1,Dial(IAX2/iaxmodem/+442055446677)
exten => _0000.,1,Dial(IAX2/iaxmodem/${EXTEN})

This simply sends all incoming calls starting with 0000 to iaxmodem/called-number and faxes for the two DIDs +4969… and +4420… also to iaxmodem, passing the called number statically. The magic happens in /var/spool/hylafax/etc/FaxDispatch:

LANG=de_DE
DEST_EMAIL=$(/bin/grep $CALLID4 /etc/hylafax/emails.txt | awk ‘{print $2}’)
FEILTUEP=$(/bin/grep $CALLID4 /etc/hylafax/emails.txt | awk ‘{print $3}’)
if [ “$DEST_EMAIL” == “” ];
then

GNFAX=$(echo $CALLID4 | cut -b 1-4)
if [ “$GNFAX” = “0000” ];
then
SENDTO=$(echo $CALLID4 | sed ‘s/^0000//g’ | sed ‘s/1111/@/g’)
FILETYPE=pdf
else
SENDTO=fax-incoming@company.com
FILETYPE=pdf
fi

else
SENDTO=$DEST_EMAIL
FILETYPE=$FEILTUEP
fi

And this is /etc/hylafax/emails.txt:

+496980001234 hans@company.com pdf
+442055446677 jeff@company.com pdf

What happens is: call (fax) is coming in to +496980001234 – send it to iaxmodem/+496980001234 – pass it to HylaFax – HylaFax “FaxDispatch” script looks up in /etc/hylafax/emails.txt whether we know the called number +496980001234. If so, we also know the eMail address – hans@company.com – and the format – pdf – and HylaFax sends the received fax out to that eMail address in that format. Format can be pdf or tif. But now, if someone faxes to 0000john1111anothercompany.net then Asterisk will pass “0000john1111anothercompany.net” to iaxmodem and therefore to HylaFax “FaxDispatch”, which will do the following: if the called number was not found in /etc/hylafax/emails.txt and the called number starts with 0000, strip off 0000 and replace 1111 with the @ sign. Which translates into an useable eMail address: john@anothercompany.net. This is where the fax will be sent. If the called number does not start with 0000 and it was not found in emails.txt either, then send it to a fallback address: fax-incoming@company.com. To sum up:

1. Manage static users in /etc/hylafax/emails.txt: DID, eMail address, format of attachment
2. The eMail address of the fax recipient will be resolved dynamically for all calls that start with 0000
3. If no match in emails.txt and the called number doesn’t start with 0000, send the fax to a fallback eMail address.