For Programmers: Free Programming Magazines  


Home > Archive > PERL CGI Beginners > May 2004 > sendmail/cgi issue









You are viewing an archived Text-only version of the thread. To view this thread in it's original format and/or if you want to reply to this thread please [click here]

 

Author sendmail/cgi issue
Joe Cipale

2004-05-22, 11:30 am

I have a file that is generated via CGI. Once the user is happy with the
file, I want to send the file to a dedicated email address. The problem
is this. Once the user decides to process the file and send it off to
the email address, the file inforamtion IS NOT included in the body of
the email that is delivered.

The funny thing is, I can encode/use this (code below) simply as a
generic perl script, and the data is delivered as expected. It is not
being collected and deliverd from with the CGI script via the web.

Can someone tell me what I am missing here?
You can email me directly if you wish. Thanks in advance,

Joe Cipale
--
open(FILE, "$read_path/$dte");
open(SM, "| /usr/sbin/sendmail -t -fjoec\@aracnet.com");
my @email_body = <FILE>;
print "@email_body";

print SM <<EOF;
From: evbc\@aracnet.com
To: joec\@aracnet.com
Subject: Race Refund Request

EOF

print SM @email_body; # Here's where the body gets
# printed into the message.
close(FILE);
close(SM);

#----------------------------------------------------------#
# "Don't fear the penguin!" #
#----------------------------------------------------------#
# Registered Linux user: #309247 http://counter.li.org #
#----------------------------------------------------------#
David Efflandt

2004-05-22, 11:30 am

On Fri, 26 Mar 2004 11:00:53 -0800, Joe Cipale <joec@aracnet.com> wrote:
> I have a file that is generated via CGI. Once the user is happy with the
> file, I want to send the file to a dedicated email address. The problem
> is this. Once the user decides to process the file and send it off to
> the email address, the file inforamtion IS NOT included in the body of
> the email that is delivered.
>
> The funny thing is, I can encode/use this (code below) simply as a
> generic perl script, and the data is delivered as expected. It is not
> being collected and deliverd from with the CGI script via the web.
>
> Can someone tell me what I am missing here?
> You can email me directly if you wish. Thanks in advance,


You are missing the test to see if your open() is successful, and print
the error $! somewhere useful (like to the browser) if not. Assuming you
are setting a proper Content-type header before this, does the body
content show up in the browser (from the: print "@email_body";)?

> Joe Cipale
> --
> open(FILE, "$read_path/$dte");
> open(SM, "| /usr/sbin/sendmail -t -fjoec\@aracnet.com");
> my @email_body = <FILE>;
> print "@email_body";
>
> print SM <<EOF;
> From: evbc\@aracnet.com
> To: joec\@aracnet.com
> Subject: Race Refund Request
>
> EOF
>
> print SM @email_body; # Here's where the body gets
> # printed into the message.
> close(FILE);
> close(SM);
>
> #----------------------------------------------------------#
> # "Don't fear the penguin!" #
> #----------------------------------------------------------#
> # Registered Linux user: #309247 http://counter.li.org #
> #----------------------------------------------------------#



--
David Efflandt - All spam ignored http://www.de-srv.com/
http://www.autox.chicago.il.us/ http://www.berniesfloral.net/
Tad McClellan

2004-05-22, 11:30 am

Joe Cipale <joec@aracnet.com> wrote:

> The funny thing is, I can encode/use this (code below) simply as a
> generic perl script, and the data is delivered as expected. It is not
> being collected and deliverd from with the CGI script via the web.



Does the CGI program run as a different user than when you use
the command line?

You can try running this both ways to find out:

my $login = getpwuid($< );
print "my login ID is '$login'\n";


> Can someone tell me what I am missing here?



Some difference in the environment (permissions, paths, env vars...).


--
Tad McClellan SGML consulting
tadmc@augustmail.com Perl programming
Fort Worth, Texas
Tad McClellan

2004-05-22, 11:30 am

Joe Cipale <joec@aracnet.com> wrote:


> --



Please don't put non-sig stuff below the sig-dash.

It makes it hard to quote on many newsreaders.


> open(FILE, "$read_path/$dte");



You should always, yes *always*, check the return value from open():

open(FILE, "$read_path/$dte") or die "could not open '$read_path/$dte' $!";


> open(SM, "| /usr/sbin/sendmail -t -fjoec\@aracnet.com");



You won't have to mentally filter out backslashes if you don't
put backslashes in in the first place:

open(SM, '| /usr/sbin/sendmail -t -fjoec@aracnet.com') or die ...

> my @email_body = <FILE>;
> print "@email_body";



That will print an extra space character at the beginning of
every line except the first line.

Is that what you want it to do?


> print SM <<EOF;
> From: evbc\@aracnet.com
> To: joec\@aracnet.com
> Subject: Race Refund Request
>
> EOF


You won't have to mentally filter out backslashes if you don't
put backslashes in in the first place:

print SM <<'EOF';
From: evbc@aracnet.com
To: joec@aracnet.com
Subject: Race Refund Request

EOF


--
Tad McClellan SGML consulting
tadmc@augustmail.com Perl programming
Fort Worth, Texas
Joe Smith

2004-05-22, 11:30 am

Joe Cipale wrote:

> I have a file that is generated via CGI. Once the user is happy with the
> file, I want to send the file to a dedicated email address. The problem
> is this. Once the user decides to process the file and send it off to
> the email address, the file inforamtion IS NOT included in the body of
> the email that is delivered.


That's exactly what will happen if the open() fails (which you do not
check for).

> open(FILE, "$read_path/$dte");


Make that

my $open_failure = "";
open FILE, "$read_path/$dte" or ($open_failure = "Unable to read file
$read_path/$dte - $!\n";

Then change

> print SM @email_body;


to

print SM $open_failure,@email_body;

so that the error message will be sent on failure.
-Joe
Sponsored Links







Also available: Server administration forum archive | Web Design forum archive | Software forum archive | Hardware reviews archive

Copyright 2008 codecomments.com