Kangry.com [insert cool graphic here]
home | Topics | Logout | Search | Contact | ?? Kangry ?? | Bandwitdh
Topics:
DVR
nvrec
Mplayer
Links
Misc
Commands
Humor

Name

Password

New user

uploaded files
(misc)-> efax to email submited by Russell Sat 29 Jan 05
Edited Fri 13 Jan 12
Web kangry.com

How do I set up a fax modem to receive faxes then convert them into email?

Rant and Essay: (skip if you just want an answer to the question )

On the face of it, this seems like a silly question. Why not just get the originator to send you the content as an email in the first place. In many cases this is quite possible, however not every industry has actually modernized. Keep in mind, there are a lot of people out there still using DOS (not denial of service, but rather Disk Operating System) My wife works with some people who are still in this technological dark age.

Previously she had a Cannon Multipass C3500. This is a simple ink jet fax/scan/copier that lasted several years. One really nice feature that this (the C3500) had is that it can be configured to receive incoming faxes into the attached computer. There are several reasons you might want to do this:

  • ink jet ink is much more expensive than laserjet ink, so it is cheaper to print on a different printer.

  • If you get on a junkmail fax list, it's nearly impossible to get off of the list (trust me I've tried) so why should you waste expensive ink jet ink on junkmail faxes. (much better to just delete them in the computer.)

  • If you have the fax in digital format, you can save it digitally or forward it to someone via email, moving to a more modern technology.

We decided to replace the C3500, and went shopping. We settled on the HP Office Jet 5510 all-in-one (HP 5510)

But it is missing this critical feature. We checked the web pages and even contacted tech support. And they told us that the entire HP fax line does NOT have a "do not print incoming faxes" option. It will save faxes to memory so you can save and forward them digitally but, you still have to waist ink on them.

I am CONVINCED that this choice is deliberate. All the ink jet manufactures clearly make money on the ink. Ink jet printers are frequently "free with rebate" or "free with computer" and the reason they are willing to do that is that they make lots of money selling 4ml of ink for $40. It really is a scam.

I checked around, looked on the Brother and Lexmark sites. I could be wrong, but near as I can tell, the similar products from the other manufactures have the same limitation.

End of Rant.

So what do I do about it ?

It turns out that its actually quite simple to receive faxes with linux and send them out as email. But frustratingly there exists no simple How-To start to finish on how to do it.

I started out with an old linux box, currently running Redhat 9.0 (yes it's obsolete, but it is behind a firewall and all I use it for is a home-lan fileserver, and now fax-to-email. )(update 11/06: I migrated the fax 2 email function to a new box running fedora 6, using these notes. No problems encountered, except that my old ISA modem was useless, so I switched to an external faxmodem connected to /dev/ttyS0 ) and in this machine I have an old fax modem. Might even be a 33.6 modem instead of 56k. It's been a long time since I've used it as a modem, but the critical thing here is that it is an old modem that linux can use. Most modern modems are "WinModems" which do not have linux drivers. If you need to buy a modem, you have to get one that supports linux. It will cost more, and to make matters worse, not all the "product specifications" pages even mention linux. A friend pointed out one at Circuit City by BestData that does not mention linux on the box, and says it requires windows, but apparently the website says it is supported under linux. Bottom line: research first, then buy.

The next part is easy. It turns out that efax is included in the Red Hat 9 distro. (it's probably in newer versions, and even if it isn't you can download and install it from the efax page )

Now the efax documentation is a little sketchy.

But it told me how to add efax as a service that will answer calls. I just added the line:

## line for efax
s1:45:respawn:/bin/sh /usr/bin/fax answer

to the end of /etc/inittab. (to make chenges take effect, use telinit q , as root and init will re-read /etc/inittab )

which works fine. When the machine boots, it starts the fax process and when the fax line rings it answers the phone and receives the faxes to /var/spool/fax (efax assumes that the faxmodem is /dev/modem if it isn't, a symlink will fix it (ln -s /dev/ttyS0 /dev/modem does it for me )

that part works great. But the problem is the "send as email" part. The efax docs mention that the efax can be configured to do this, but don't go on to say how. In fact, the docs mention the /etc/efax.rc configuration file, but no sample of the file is given. So I had no idea what even is supposed to go into the file.

I found a efax.rc file here, but it too was missing some pieces of the puzzle.

That one contained the lines :
# The user to be sent mail when a fax is received.
FAXMGR=$USER
# The sendmail executable including full path if necessary. Only
# required if forwarding received faxes by e-mail in $NOTIFY.

SENDMAIL=/usr/sbin/sendmail

# The command to execute when a fax is received. Normally this
# sends FAXMGR e-mail or prints the received fax. The variable
# $f will be the name of the log file, $FILES will contain the
# names of the received files, and $REMID will have the remote ID
# string or '?' if none. The faxmail function will e-mail the fax
# as MIME image/tiff attachments. Comment this out to do
# nothing. Protect with single quotes.

NOTIFY='faxmail "$REMID" "$f" $FILES | $SENDMAIL $FAXMGR
# NOTIFY='mail -s "fax/message from $REMID: $FILES" $FAXMGR <$f'
# NOTIFY='lpr $f ; $FAX print $OPT $FILES'

with these three "notify" options. The "faxmail" comand looks like what we want, but sadly, I couldn't figure where the "faxmail" command was supposed to be. It wasn't installed as part of efax.

I changed the "NOTIFY" line to this:

NOTIFY='uuencode $FILES fax.tif |mail -s "fax/message from $REMID: $FILES" $FAXMGR '

(uuencode is part of sharutils, which is included in most distros, but not necessarily part of the default install. )

and that almost works, but it has a few problems: 1)this only works one page faxes. 2) the attached tif file is not auto viewed by our mail client ( mozilla ) so you have to double click on it to view it in a new window. 3) because the image is actually a fax encoded tif the aspect ratio is wrong.


So I resorted to a simple perl script and that solved the problem.

My NOTIFY line:
NOTIFY='/root/fax2mail.pl $REMID $FILES'

( actually this is the only line in my /etc/efax.rc that isn't a comment )

my simple perl script : (/root/fax2mail )


#!/usr/bin/perl
$SENDTO="XXXXX\@YYYY.com"
$faxfrom="$ARGV[0] $ARGV[1] $ARGV[2] $ARGV[3] $ARGV[4] $ARGV[5] $ARGV[6] $ARGV[7] $ARGV[8] $ARGV[9] $ARGV[10]";
$faxfrom=~s/ / /g; ## remove extra blanks
$faxfrom=~s/ / /g;
$faxfrom=~s/ / /g;
$faxfrom=~s/ / /g;
$faxfrom=~s/ / /g;
$n=1;
$isopen=0; ## don't bother sending mail if no fax pages
do {
$filename=$ARGV[$n];
if (-e $filename){
if ($isopen==0){
open (OUT,"|mail -s 'fax from $faxfrom' $SENDTO");
$isopen++;
};

$x=`convert $filename /tmp/fax.png`;
$outfile="$filename".".png";
open (IN,"uuencode /tmp/fax.png $outfile |");
do{$line=<IN>;print (OUT $line); }until (eof(IN));
close (IN);
};

$n++;
}until ($n>=(@ARGV));
close (OUT);

-----------


change $SENDTO="XXXXX\@YYYY.com" to where you want the faxes sent. Don't forget to use \@ ( I lost some time to this pitfall )


It's not the most elegant, but it works. It calls "convert" to convert the tiffg3 format to a png. (convert is included in imagemagick which is included in most distros ) . The script doesn't open the mail command until it knows it has an attachment to send. This script gets called even when no fax is received. ( non fax wrong number, or fax fails to make connection ) I saw no reason to send an empty email.

The result works quite well. Incoming faxes are converted to email attachments that are visible within mozilla when the email is opened. The subject contains the phone number the fax came from ( the $REMID variable on the NOTIFTY line, this is the number the sending fax machine sends, it's not based on callerid, so it could be incorrect )

Possible problems:

  • I never clean up /var/spool/fax, so that could possibly fill up disk space,but at 40k per fax page and only 10/15 pages per day it will take a while. But a cron job should be add to discard old fax files.

  • A feature present in the cannon fax receipt program would let you rotate faxes sent upside down or sideways. I have no idea how to achieve this when the fax is sent as a mail attachment.

  • Because the $REMID is passed though a shell, it's might be possible that someone could issue a command (as root) though creative setting of the sender's fax machine's phone number identifier. I don't know what character limitation that field has nor how long it can be. This is more of a amusing thought exercise than a real security problem.


Possible additions:

  • I'd like to add an address book feature so that if a fax comes from a known fax number the email has the name in the subject and a logical return address.

A version of the fax2email script in bash [warning, It's in German, but the code is easy to read regardless of language]



Replys:
fax2mail script (mwrsa)

Add comment or question...:
Subject:
Submited by: NOT email address. Leave blank for anonymous    (Spam Policy)

Enter Text: (text must match image for posting)




This file (the script that presented the data, not the data itself) , last modified Wednesday 03rd of December 2014 09:40:39 AM
your client: CCBot/2.0 (http://commoncrawl.org/faq/)
current time: Friday 15th of December 2017 01:23:18 AM