Valkerri has asked for the wisdom of the Perl Monks concerning the following question:

Thank you in advance for your help. This site has been a godsend.

Ever had an ISP not return your calls? Well I have stripped down this script to its barest bones trying to get it to work on a box that I can get no information about and to which I am allowed FTP access only. The script runs so permissions are OK, right? But the following code dies at line 20 so it specifically has a problem with some aspect of Sendmail? This script ran on another box just fine.

So, what could I try assuming I will never get an answer from the ISP? Time is running out on this project.

#!/usr/bin/perl -w use strict; use CGI qw(:standard); my $request = new CGI; my $emailaddress = "me\@mydomain.com"; my $emailaddress2 = "client\@clientdomain.com"; my $htmlpagegood = '<html><head><title>TITLE</TITLE></head><body><P>HI +</body></html>'; my $htmlpagebad = '<html><head><title>TITLE</TITLE></head><body><P>BYE +</body></html>'; open(MAIL, "|/usr/lib/sendmail -t") or die "Content-type: text/html\n\ +n\n$htmlpagebad"; print MAIL "To: $emailaddress\n"; print MAIL "From: $emailaddress2\n"; print MAIL "Subject: subjectmatter\n"; print MAIL "Content-type: text/plain\n\n"; print MAIL "bodytext\n\n"; close(MAIL) or die "Content-type: text/html\n\n\n$htmlpagebad"; print "Content-type: text/html\n\n\n$htmlpagegood"; exit;

Replies are listed 'Best First'.
Re: Sendmail in a Blackbox
by Trimbach (Curate) on Aug 05, 2001 at 09:13 UTC
    It's entirely possible that your ISP either a) doesn't have sendmail installed, b) doesn't allow you to use it, or c) DOES allow you to use it, but installed it in a non-standard place (that is, other than /usr/lib/sendmail).

    But that's ok. There's many more ways to skin a cat. Check out the Mail::Mailer module to help you out. This module will actually search for whatever mail program is on your ISP and use what it finds. Sendmail isn't the only game in town, and if your ISP has mailx, mail, or Mail you're in business. And if none of those work, the module also lets you send mail directly through an SMTP server (assuming you have access to one somewhere, perhaps through your personal email account?) The documentation is pretty good, it's easy to use, and it's good to get used to platform-independent e-mail. Enjoy!

    Gary Blackburn
    Trained Killer

Re: Sendmail in a Blackbox
by mitd (Curate) on Aug 05, 2001 at 10:07 UTC
    Always frustrating with only ftp access. Here are a couple of things you can try.
    1. Add $! to end of your die's to see if error message gives you any clues.
    2. send a test mail using pipe to Mail or mail this will verify to a certain extent if local accounts can send mail from that host plus headers may give a clue as to what MTA is being used.
    3. Try looking for sendmail in /usr/sbin which is becoming more popular OR try opening sendmail without an absolute path, a long shot but worth a try.
    4. several other places I have seen sendmail reside:
      1. /usr/bin, /etc, /var/lib
      2. /usr/local/bin ./etc ./sbin ./lib
    5. you try shell script which -a sendmail > sendmailplace.
    Hope this helps.

    mitd-Made in the Dark
    'My favourite colour appears to be grey.'

Re: Sendmail in a Blackbox
by rob_au (Abbot) on Aug 05, 2001 at 11:59 UTC
    I've had a situation similar to this, where I have not wanted to have to depend on (guessing) the path location of sendmail on a remote box. To solve this, I opted for the usage of Mail::Mailer (in conjunction with Net::SMTP). This combination allowed me to make use of existing mail infrastructure in place in the remote location and saved me having to fumble my way through finding the local installation of sendmail (if indeed it did exist - I still don't know).
     
    The equivalent code to that posted using Mail::Mailer and Net::SMTP would be:
    my ($smtp) = Mail::Mailer->new("smtp", Server => "127.0.0.1"); $smtp->open({ 'To' => $emailaddress2, 'From' => $emailaddress, 'Subject' => "subjectmatter", 'Content-Type' => "text/plain", }); print $smtp "bodytext\n\n"; $smtp->close;
    Make sure of course to replace the IP address 127.0.0.1 with that of your ISP's mail server - Also too, it may be worthwhile, particularly in the early stages of project rollout, to include a 'Cc' => $emailaddress line in the hash passed to Mail::Mailer so that you can confirm delivery of mail to your client.
     
    Good luck!
     

     
    Ooohhh, Rob no beer function well without!
Re: Sendmail in a Blackbox
by toma (Vicar) on Aug 05, 2001 at 10:13 UTC
    Your script would fail at line 14 if sendmail was in a nonstandard place or if you couldn't execute it. A typical cause of failure to close a file is insufficient disk space.

    You could try substituting another program for sendmail and see if that works.

    You can look in /etc/sendmail.cf to see how sendmail is configured.

    For development without a shell you could write a cgi that does something evil. This cgi would execute an arbitrary shell command on the server and display the result in the browser. An example use for the program is to see if the server is out of disk space.

    Make sure you delete this evil arbitrary-command cgi as soon as possible, since the server people won't be too happy if they find it lying around. This type of evil program is a good example of how too-tight security causes users to bypass security and create a weaker system. Don't tell anyone that I told you to write this program, since it could get you fired or convicted of some sort of felony.

    It should work perfectly the first time! - toma

Re: Sendmail in a Blackbox
by strredwolf (Chaplain) on Aug 05, 2001 at 10:00 UTC
    Your ISP may have a time limit of some seconds before it autokills a script. I'd check the other suggestions first, while doing some server speilunking, before assuming this, though.

    --
    $Stalag99{"URL"}="http://stalag99.keenspace.com";

Re: Sendmail in a Blackbox
by tachyon (Chancellor) on Aug 05, 2001 at 19:28 UTC

    This does not help with your question but may help anyway. In Perl you can use herepages to avoid lots of print statements and quoting clutter. Here is an example

    my $mail_prog = '/usr/lib/sendmail'; my $sender = 'me@mine.com'; my $recipient = 'you@yours.com'; my $subject = 'Shopping'; open (MAIL, "|$mail_prog -t -i") or die "Can't open $mail_prog $!"; print MAIL<<MESSAGE; To: $recipient Reply-to: $sender From: $sender Subject: $subject Thanks for shopping with Perlmonks love vroom MESSAGE close MAIL;

    As you can see we print everything from the <<MESSAGE to the closing MESSAGE token. The closing token needs to be on a line by itself - no semicolon. You can use almost any token you want. If you do <<MESSAGE or <<"MESSAGE" then variables will interpolate. If you do <<'MESSAGE' they will not. You can include " in the herepage without the need to escape them with a \ so this is pretty cool. You can also assign to a variable with a herepage like $message =<<MESSAGE ....

    This makes code much easier to read.

    cheers

    tachyon

    s&&rsenoyhcatreve&&&s&n.+t&"$'$`$\"$\&"&ee&&y&srve&&d&&print

Re: Sendmail in a Blackbox
by trantor (Chaplain) on Aug 06, 2001 at 01:47 UTC

    I definitely agree with the others on using Mail::Mailer or equivalent instead, but a quick fix (specially if running under some sort of Linux distribution) could be replacing /usr/lib/sendmail with /usr/sbin/sendmail

    -- TMTOWTDI

      THANK YOU!! That did it! Whew! Job saved in nick of time by heroic scribe. You weren't kidding when you said "quick fix." Thank you (ad infinitum)