HylaFAX The world's most advanced open source fax server

[Date Prev][Date Next][Thread Prev][Thread Next] [Date Index] [Thread Index]

[hylafax-users] Mail to fax gateway



For those struggling with mail to fax gateway, this might be your ticket out of that madness.

Here we go:
1. Create new user, e.g. faxgw, create .forward file in his homedir, and put there something like this: "|/var/spool/hylafax/bin/faxgw" (with quotes and pipe too)
2. create new file, /var/spool/hylafax/bin/faxgw, chmod it to -rwxr-xr-x , and put this perl script in there (note: this is modified script i've found in this forum. I do not take much credit for this).


#!/usr/bin/perl
use MIME::Parser;
use POSIX;

my $tmp = "/tmp/mail-$$";
mkdir $tmp, 0700;
my $log_file = "/var/log/faxgw";

my $parser = new MIME::Parser;
$parser->output_under($tmp);

my $entity = $parser->parse(\*STDIN);

my @parts;
my @entities = ($entity);

while ($_ = shift(@entities))
{
    my @p;
    if (@p = $_->parts)
    {
        unshift @entities, @p;
    } else
    {
        push @parts, $_;
    }
}

my $from = $entity->head->get('From'); $from =~ s/\n//go;
my $oldsubject = $entity->head->get('Subject');
$oldsubject =~ s/\[(\d+)\]\s*(.*)//go;
$number = $1;
my $subject = $2;

system( "sendfax",
        "-n",
        "-f", $from,
        "-r", $subject,
        "-d", $number,
        map ({$_->bodyhandle->path() } @parts)
);

system("/bin/rm", "-rf", $tmp);

my $logmessage = strftime("%d.%m.%Y %H:%M:%S", localtime) . " Sent fax, from: $from, to: $number, regarding: $subject.\n";
open (my $log, ">>", $log_file) || die "Could not open $file for append: $!";
print $log $logmessage;
close $log;
###################################################################################################



3. Google for and download any perl modules this script requires to run (I don't remember which ones, there should be some 3 of them, google for MIME::Parser).


4. Create /var/log/faxgw file, chown it to faxgw:faxgw if you want some basic usage reporting.

5. From now on you should be able to send faxes (plaintext + multiple ps/pdf, you will have to add converters for other attachment formats to hylafax typerules file) assuming your mail header looks like this:

To: faxgw@xxxxxxxxxxxxxxxxxxx (faxgw is the name of user you've created)
Subject: [destinationnumber] Your very own subject here
where [destinationnumber] is number you want to fax to surrounded by square brackets (eg. [00123444555666]).
Check logs whether everything went ok.



Anything unclear, any suggestions, improvements? Bring it on. Or just send me some flowers.


PS. Anyone with some info regarding word/html to PS converters and how to set them up for hylafax?


-- Vladimir Lascik --


____________________ HylaFAX(tm) Users Mailing List _______________________ To subscribe/unsubscribe, click http://lists.hylafax.org/cgi-bin/lsg2.cgi On UNIX: mail -s unsubscribe hylafax-users-request@xxxxxxxxxxx < /dev/null *To learn about commercial HylaFAX(tm) support, mail sales@xxxxxxxxx*




Project hosted by iFAX Solutions