Programming Forums
User Name Password Register
 

RSS Feed
FORUM INDEX | TODAY'S POSTS | UNANSWERED THREADS | ADVANCED SEARCH

Reply
 
Thread Tools Display Modes
Old Sep 19th, 2006, 12:30 PM   #1
Pizentios
Programming Guru
 
Pizentios's Avatar
 
Join Date: May 2004
Location: Brandon, Manitoba, Canada
Posts: 2,023
Rep Power: 7 Pizentios is on a distinguished road
Send a message via ICQ to Pizentios Send a message via MSN to Pizentios
Mail::Sender Problems

Hey,

So i have been working on a fax server for my company, so we can get rid of some of huge amounts of paper around here. I have hylafax setup and working perfectly. I have written a perl script that uses OCR software to read the incomming cover sheets and email the respective user on the cover sheet a pdf version of their fax (ofcourse if the cover sheet is has hand writing on it instead of text the OCR part doesn't work and it emails it to a default user for routing).

Anyways, i pretty much have it working. However when it goes to send the email (with the fax attached), Mail:ender gives me the error:

Quote:
Originally Posted by Mail::Sender
File "File" not found
It's caused by this line:
(ref ($sender->MailFile(to => $default_mail, subject => 'New Fax!', msg => 'Please see attached file for your fax.', File => $file)) and print "Mail Sent OK!") or die $Mail::Sender::Error, "\n";
here's the whole script:
#!/usr/bin/env perl
#
#########################################################################################
## Purpose: This script handles all the routing and emailing of faxes that are recived.##
## Author: Pizentios                                       ##
## Date Created: 2006-09-12                                   ##
## File Name: fax-route.pl                                   ##
#########################################################################################


use Pg;
use Mail::Sender;
use File::Copy;

#log searching patterns. 
my $log_patterns = "RECV FAX: bin\/faxrcvd";
#location of where the faxes get stored. 
my $fax_location = "/var/spool/fax/recvq";
#location of work dir.
my $work_dir = "/root/scripts";
#file name for OCR output.
my $output_name = "output";
my $pass = 1;
#mail settings:
my $smtp_host = "XXXXXXXX";
my $from = "XXXXXXXX";
my $reply_address = "XXXXXX";
my $default_mail = "XXXXXXXX";

#db connection stuff:
##$con_val[0] == the database name.
##$con_val[1] == the host.
##$con_val[2] == the port.
##$con_val[3] == the username for the database.
##$con_val[4] == the password for the database.
my @conn_val = ("fax", "XXXXXX", "XXXX", "XXXXXX", "XXXXX");

#SMTP mail stuff:
my $sender = new Mail::Sender (smtp => $smtp_host, from => $from, replyto => $reply_address);

#connect up to the db.
my $conn = Pg::connectdb("host=" . $conn_val[1] . " port=" . $conn_val[2] . " dbname=" . $conn_val[0] . " user=" . $conn_val[3] . " password=" . $conn_val[4]);
##check connection.
if ($conn->status != PGRES_CONNECTION_OK)
{
        die "Failed to connect: ".-$conn->errorMessage."\n";
}

#monitor the logs to see when a fax is comming in. 
open (TAIL, "tail -f /var/log/messages 2>&1 |") or die "can't open pipe:$!";

while(<TAIL>)
{
    #loop and watch the log all the time. 
    if ($_ =~ m/$log_patterns/)
    {
        #returns true if we have a match on $_
        #now we need to grab the file name of the new fax.
        $_ =~ m/fax[0-9][0-9][0-9][0-9][0-9][0-9][0-9][0-9][0-9].tif/;
        $file_name = $&;
        copy("$fax_location/$file_name", "$work_dir/$file_name") or die "Copy Failed....";
        @args = ("tesseract", "$work_dir/$file_name", "$work_dir/$output_name");
        system(@args); # or die "OCR Software Failed..."; #run OCR software and dump output to a file. 
        #it quits here. 
        print "Test2\n";
        open (FAX, "$work_dir/$output_name.txt") or die "Couldn't open OCR output file..."; #open OCR output file.
        my @lines = <FAX>; #dump OCR output into an array.
        close (FAX); #close the OCR output file. 
        print "Test3\n";
        my $result = $conn->exec("SELECT * FROM rules"); #grab our search rules from the db.
        foreach $line (@lines)
        {
            print "Test4\n";
            #loop through the lines of the fax cover sheet.
            while (@row = $result->fetchrow)
            {
                print "Test5\n";
                #loop through the search patterns from the database and see if anything matches.
                #TODO: Fix regex matching here to enable emailing to respective user. 
                if ($line =~ m/$row[1]/)
                {
                    print "Test6\n";
                    #if we have a match set pass var and exit loops.
                    #0 = true;
                    $effected_users = $row[2];
                    $pass = 0;
                }
            }
            if ($pass == 0)
            {
                #we had a match, exit loops.
                last;
            }
        }
        #make the new file name:
        $old_file_name = $file_name;
        $file_name =~ s/.tif/.pdf/g;
        #convert the fax .tif file to pdf format for easy viewing.
        system ("convert $work_dir\/$old_file_name $work_dir\/$file_name");# or die "Convertion of fax .tif to .pdf failed...";
        if ($pass == 0)
        {
            print "Test1\n";
            #grab effected users from the database. 
            my @users = split(/,/, $effected_users);
            foreach $user (@users)
            {
                if ($user != "")
                {
                    $result = $conn->exec("SELCT * FROM users WHERE idx=$user");
                    @row = $result->fetchrow;
                    $To .= $row[3] . ",";
                }
            }
            chop $To;
            #mail to the matched users.
            print "Test7\n";
            (ref ($sender->MailFile(to => $To, subject => 'New Fax!', msg => 'Please see attached file for your fax.', file => "$work_dir\/$file_name")) and print "Mail Sent OK!") or die $Mail::Sender::Error, "\n"; 
        }
        else
        {
            print "Test8\n";
            #mail to default fax user (the user that directs all non-match faxes)
            my $file = "$work_dir\/$file_name";
            (ref ($sender->MailFile(to => $default_mail, subject => 'New Fax!', msg => 'Please see attached file for your fax.', File => $file)) and print "Mail Sent OK!") or die $Mail::Sender::Error, "\n";
        }

    }
}
Anyways, i don't understand why it can't find the file. I have tried several methods of passing the location of the file to the Mail:ender object, but all have failed. Do any of you guys have any ideas?

Thanks in advance.
__________________
Profanity is the one language that all programmers understand.

Check out my Blog <---updated Nov 30 2007!
Pizentios is offline   Reply With Quote
Old Sep 19th, 2006, 12:56 PM   #2
sarumont
Hobbyist Programmer
 
sarumont's Avatar
 
Join Date: Apr 2004
Location: /dev/urandom
Posts: 154
Rep Power: 5 sarumont is on a distinguished road
Send a message via ICQ to sarumont Send a message via AIM to sarumont Send a message via Yahoo to sarumont
Looking at the Mail:ender documentation, the value in the MailFile hash should be 'file', not 'File'. See if changing the case of your 'f' helps.
__________________
"Time is an illusion. Lunchtime doubly so."
-the late, great Douglas Adams
sarumont is offline   Reply With Quote
Old Sep 19th, 2006, 1:30 PM   #3
Pizentios
Programming Guru
 
Pizentios's Avatar
 
Join Date: May 2004
Location: Brandon, Manitoba, Canada
Posts: 2,023
Rep Power: 7 Pizentios is on a distinguished road
Send a message via ICQ to Pizentios Send a message via MSN to Pizentios
It does it even if it is 'file'
__________________
Profanity is the one language that all programmers understand.

Check out my Blog <---updated Nov 30 2007!
Pizentios is offline   Reply With Quote
Old Sep 19th, 2006, 1:47 PM   #4
Pizentios
Programming Guru
 
Pizentios's Avatar
 
Join Date: May 2004
Location: Brandon, Manitoba, Canada
Posts: 2,023
Rep Power: 7 Pizentios is on a distinguished road
Send a message via ICQ to Pizentios Send a message via MSN to Pizentios
Well, after a few more tests, it's looking like this might be a bug in Mail:ender.
__________________
Profanity is the one language that all programmers understand.

Check out my Blog <---updated Nov 30 2007!
Pizentios is offline   Reply With Quote
Old Sep 19th, 2006, 5:18 PM   #5
Pizentios
Programming Guru
 
Pizentios's Avatar
 
Join Date: May 2004
Location: Brandon, Manitoba, Canada
Posts: 2,023
Rep Power: 7 Pizentios is on a distinguished road
Send a message via ICQ to Pizentios Send a message via MSN to Pizentios
i figured out what it was with a little help from dizzutch. Aparently i was sending the Mail:ender constructor a list type, when in reality i needed to send a hash type. Simply chanded the () in the constructor part to {}
__________________
Profanity is the one language that all programmers understand.

Check out my Blog <---updated Nov 30 2007!
Pizentios is offline   Reply With Quote
Reply

Bookmarks

« Previous Thread in Forum | Next Thread in Forum »

Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
 
Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Forum Jump

Similar Threads
Thread Thread Starter Forum Replies Last Post
Problems reading and writeing to a datafile Evenfall Delphi 14 May 18th, 2006 5:21 AM
problems loading 2 dlls in Delphi7 nico765 Delphi 0 Jan 7th, 2006 3:03 PM
New Switch, FTP Problems ViOLATiON Coder's Corner Lounge 6 Sep 13th, 2005 1:44 PM
C++ and Fortran Compilation problems wallygato11 C++ 0 Jul 8th, 2005 10:44 PM
c struct : problems whit structs containing each other mevuorin C 10 Jul 7th, 2005 1:05 PM




DaniWeb IT Discussion Community
All times are GMT -5. The time now is 7:38 AM.

Powered by vBulletin® Version 3.7.0, Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
Copyright ©2007 DaniWeb® LLC