Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > Perl > Perl Misc > Please help newbie with sendmail problem !

Reply
Thread Tools

Please help newbie with sendmail problem !

 
 
Jake Gourd
Guest
Posts: n/a
 
      06-04-2004
hey,

Im trying to make a cgi script work on host europe server, as far as i
know the snedmail path is correct and cgi is running correctly (a
simple print works). When I run the code below it just says

The server encountered an internal error or misconfiguration and was
unable to complete your request

on the screen, you can see this by visiting the url

http://www.goodprint.co.uk/cgi_bin/test.cgi

Please help im going mad !

#!/usr/bin/perl

print "Content-type: text/html\n\n";

print "Hello, world!\n";


open(SENDMAIL, "/usr/sbin/sendmail") or die "Cannot open $sendmail:
$!";
print SENDMAIL "(E-Mail Removed)";
print SENDMAIL "test subject";
print SENDMAIL "(E-Mail Removed)";
print SENDMAIL "Content-type: text/plain\n\n";
print SENDMAIL "The content";
close(SENDMAIL);
 
Reply With Quote
 
 
 
 
Jack Challen
Guest
Posts: n/a
 
      06-04-2004
Jake Gourd wrote:
> Im trying to make a cgi script work on host europe server, as far as i
> know the snedmail path is correct and cgi is running correctly (a
> simple print works). When I run the code below it just says



Please, please don't try calling the sendmail binary directly. It's almost
guaranteed to be a huge security hole. You should try one of the Mailing
modules on the CPAN. My current favourite is MIME::Lite.

Useful URLs:

http://cpan.org/
http://search.cpan.org/
http://search.cpan.org/~yves/MIME-Li...b/MIME/Lite.pm

Cheers
jack
 
Reply With Quote
 
 
 
 
Paul Lalli
Guest
Posts: n/a
 
      06-04-2004
On Fri, 4 Jun 2004, Jake Gourd wrote:

> hey,
>
> Im trying to make a cgi script work on host europe server, as far as i
> know the snedmail path is correct and cgi is running correctly (a
> simple print works). When I run the code below it just says
>
> The server encountered an internal error or misconfiguration and was
> unable to complete your request
>
> on the screen, you can see this by visiting the url
>
> http://www.goodprint.co.uk/cgi_bin/test.cgi
>
> Please help im going mad !
>
> #!/usr/bin/perl


Ask perl for all the help it can give you:
use strict;
use warnings;
use CGI::Carp qw/fatalsToBrowser warningsToBrowser/;

> print "Content-type: text/html\n\n";


warningsToBrowser(1);

> print "Hello, world!\n";
> open(SENDMAIL, "/usr/sbin/sendmail") or die "Cannot open $sendmail: $!";


With the CGI::Carp line above, the error message will print to your
browser. But there are at least 2 problems with this line:
You're trying to open the sendmail program, instead of opening a pipe to
it. That should be "|/usr/sbin/sendmail". Note the |
You're using a variable $sendmail that does not exist in your die
statement.


> print SENDMAIL "(E-Mail Removed)";


You need to either backslash the @, or (preferably) use single quotes
instead of double:
print SENDMAIL '(E-Mail Removed)';

> print SENDMAIL "test subject";
> print SENDMAIL "(E-Mail Removed)";


Same thing here.

> print SENDMAIL "Content-type: text/plain\n\n";
> print SENDMAIL "The content";
> close(SENDMAIL);
>


With CGI::Carp and the call to warningsToBrowser, as well as the use
warnings; statement, the warnings that would be generated by those @test
and @goodprint lines will be printed as HTML comments.

Paul Lalli
 
Reply With Quote
 
Steven Smolinski
Guest
Posts: n/a
 
      06-04-2004
Jake Gourd <(E-Mail Removed)> wrote:
>
> Im trying to make a cgi script work on host europe server, as far as i
> know the snedmail path is correct and cgi is running correctly (a
> simple print works). [...]


perldoc -q 500

> #!/usr/bin/perl


#!/usr/bin/perl -T
use warnings;
use strict;

If you're not asking perl for debugging help, you will annoy people.
Around here it's generally considered rude to ask people to do the work
of a machine.

> print "Content-type: text/html\n\n";
>
> print "Hello, world!\n";
>
>
> open(SENDMAIL, "/usr/sbin/sendmail") or die "Cannot open $sendmail:
> $!";


UUODQ: Useless Use of Double Quotes (around the sendmail path).

perldoc -q quoting vars

You probably want to write to the stdin of a running sendmail process,
not read from the file itself. Your open() statement says it wants to
be able to read from the sendmail binary itself.

See perlopentut. You might mean something like:

open SENDMAIL, '| /usr/sbin/sendmail' or die "Error piping to sendmail: $!";

> print SENDMAIL "(E-Mail Removed)";

^^^^^
Did you mean to interpolate the variable @test in there?

Warnings and strict would have told you.

> print SENDMAIL "test subject";


UUODQ

> print SENDMAIL "(E-Mail Removed)";


Did you mean to interpolate the variable @goodprint in there?

Warnings and strict would have told you.

> print SENDMAIL "Content-type: text/plain\n\n";
> print SENDMAIL "The content";
> close(SENDMAIL);


Ugh. Ugh ugh ugh. Have you seen

perldoc -q "send mail"

??

You should really read the posting guidelines for this group. They're
quite good.

Steve
 
Reply With Quote
 
Ben Morrow
Guest
Posts: n/a
 
      06-04-2004

Quoth Steven Smolinski <(E-Mail Removed)>:
> > open(SENDMAIL, "/usr/sbin/sendmail") or die "Cannot open $sendmail:
> > $!";

>
> UUODQ: Useless Use of Double Quotes (around the sendmail path).
>
> perldoc -q quoting vars


That faq has nothing to do with it; indeed, there's nothing anywhere in
the std docs on the merits of "" vs '' where there is no need for
interpolation. It is purely a matter of style.

> You probably want to write to the stdin of a running sendmail process,
> not read from the file itself. Your open() statement says it wants to
> be able to read from the sendmail binary itself.
>
> See perlopentut. You might mean something like:
>
> open SENDMAIL, '| /usr/sbin/sendmail' or die "Error piping to sendmail: $!";


You also need '-oi -t', or it won't sens mail anywhere and a . on a line
in the body will terminate the message.

> > print SENDMAIL "(E-Mail Removed)";

> ^^^^^
> Did you mean to interpolate the variable @test in there?


You're also missing newlines.

DO NOT CALL SENDMAIL YOURSELF. Use one of the modules: Mail::Sendmail,
if you don't need the fanciness of MIME::Lite.

Ben

--
Although few may originate a policy, we are all able to judge it.
- Pericles of Athens, c.430 B.C.
http://www.velocityreviews.com/forums/(E-Mail Removed)
 
Reply With Quote
 
Brian McCauley
Guest
Posts: n/a
 
      06-04-2004
(E-Mail Removed) (Jake Gourd) writes:

> Subject: Please help newbie with sendmail problem !


"Please help" and "problem" in subject lines are a pointless waste of
space. Good subject lines are very important. Wasting space in them
is seen as bad manners. Everyone wants their posts to be read - in
some newsgroups this leads to an emphasis arms-race. For this reason
any unwaranted emphasis in subject lines (such as your "!") is also
considered rudness.

The word "newbie" in subject lines will usually be read as "person too
lazy to read the FAQ" because experience has shown us that 95% of
posts with newbie in the subject are repeating FAQs.

Do not get upset me for telling you all this. I'm only trying to help
by telling you how your actions are likely to be percieved.

I should also point out that you are indeed repeating a FAQ. Do not
get upset me for telling you this either. It would be quite
irrational for you to get upset at me because of something _you_ have
done.

> open(SENDMAIL, "/usr/sbin/sendmail") or die "Cannot open $sendmail:
> $!";


Here you are opening the file /usr/sbin/sendmail for reading. For
details of the Perl open() function see "perldoc -f open".

I would guess that what you actually wanted to do is run
/usr/sbin/sendmail (with appropriate switches) as a subprocess and
pipe stuff to it.

> print SENDMAIL "(E-Mail Removed)";
> print SENDMAIL "test subject";
> print SENDMAIL "(E-Mail Removed)";
> print SENDMAIL "Content-type: text/plain\n\n";


That is not a well formed mail message header. The To header should
start "To:", the subject header "Subject:" and so on. Every header
should end with a newline.

The @ character is meta in double quotes and needs to be escaped.

As MJD famously put it: You can't just make **** up and expect the
computer to know what you mean, retardo!

For an example of correct usage of sendmail please see FAQ "How do I
send mail?". However as many others have pointed out, notwithstanding
the FAQ, you maybe better off not using sendmail directly.

--
\\ ( )
. _\\__[oo
.__/ \\ /\@
. l___\\
# ll l\\
###LL LL\\
 
Reply With Quote
 
Steven Smolinski
Guest
Posts: n/a
 
      06-06-2004
Ben Morrow <(E-Mail Removed)> wrote:
>
> Quoth Steven Smolinski <(E-Mail Removed)>:
>> > open(SENDMAIL, "/usr/sbin/sendmail") or die "Cannot open $sendmail:
>> > $!";

>>
>> UUODQ: Useless Use of Double Quotes (around the sendmail path).
>>
>> perldoc -q quoting vars

>
> That faq has nothing to do with it; indeed, there's nothing anywhere
> in the std docs on the merits of "" vs '' where there is no need for
> interpolation. It is purely a matter of style.


You are entirely correct. Thanks for that.

> DO NOT CALL SENDMAIL YOURSELF. Use one of the modules: Mail::Sendmail,
> if you don't need the fanciness of MIME::Lite.


Always a good idea. Unless you're just playing with piped opens for
laughs and giggles.

Steve
 
Reply With Quote
 
 
 
Reply

Thread Tools

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
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Re: [sendmail,perl] How to catch a mailer error [perl script as sendmail.cf mailer] Andrzej Adam Filip Perl 0 03-31-2008 09:24 PM
Unable to load tag handler class "com.cj.smtp.Sendmail" for tag "send:Sendmail" sugapablo Java 0 09-21-2007 01:41 PM
I have problem with POP3Client&Sendmail Module, Please Help. eng.john84@gmail.com Perl Misc 3 05-02-2007 04:00 PM
Need help on a sendmail contrib, qtool.pl Ninou Perl Misc 0 03-04-2004 09:11 AM
please help... ...me learn C++ please please please :) KK C++ 2 10-14-2003 02:08 PM



Advertisments