Link to home
Start Free TrialLog in
Avatar of GorGor1
GorGor1

asked on

urgent..Sendmail.pm

Our site is on a web host that DOES have sendmail.pm installed and the path is /usr/sbin.  My cgi script starts off as follows:

#!/usr/bin/perl -w
use strict;
use CGI qw(:standard);
use Mail::Sendmail;

When I run the script through Telnet (bash# perl script.cgi), it tells me that it 'Can't locate Mail/Sendmail.pm' and then it gives me a bunch of directories for perl5.  How do I put the path to sendmail.pm in the script instead of just using 'use Mail::Sendmail;'?  This is somewhat urgent.  Thanks!
Avatar of maneshr
maneshr

"...How do I put the path to sendmail.pm in the script instead of just using 'use Mail::Sendmail;'?.."

first and foremost you have to get the full directory path to Sendmail.pm

Lets say it is /usr/lib/Mail/Sendmail.pm

now you want to add /usr/lib/Mail to your default PERL search path.

you can do that in any of the following ways...


#!/usr/bin/perl -w -I/usr/lib/Mail

use Mail::Sendmail;

OR

#!/usr/bin/perl -w

BEGIN{
  push(@INC,"/usr/lib/Mail");
}

use Mail::Sendmail;

OR

#!/usr/bin/perl -w

BEGIN{
  unshift(@INC,"/usr/lib/Mail");
}

use Mail::Sendmail;

OR

#!/usr/bin/perl -w

use lib '/usr/lib/Mail';

use Mail::Sendmail;


Hope that helps.
Is it just me or doesn't that seem to be an awfully odd place to have a perl module?

Are you sure the sendmail you're seeing in the /usr/sbin directory isn't the sendmail program itself?
Avatar of GorGor1

ASKER

the guy at the web hosting place told me that 'sendmail is in /usr/sbin/'.  I bet this is where the actual program is.  Using telnet and its limited capabilities, I couln't find Mail/Sendmail.  I'm a Telnet retard, so I'm not too sure what to do.  Sendmail.pm, i would think, should be installed on their server.  How do I do a 'locate' using Telnet?  It won't let me use the locate command.  If I can find the damn sendmail.pm, I'd try maneshr's.  ("use lib '/usr/lib/Mail';" didn't work).  Thanks again!
"..sendmail is in /usr/sbin/'..."

oh!! by that he meant that the sendmail binary executable is in /usr/sbin.

However, that does not mean that the PERL module, with the same name (Sendmail.pm), is in the same directory. So chances are Sendmail.pm may or may not be there on the web hosts server.



"..How do I do a 'locate' using Telnet? .."

are you on a windows machine or Unix machine?

let me know
Avatar of GorGor1

ASKER

The site is on a Unix server.  I myself am telnetting with windows 98.
".. I myself am telnetting with windows 98..."

check in your windows directory for a file called telnet.exe.

form the DOS prompt type telnet <your UNIX server name>

when prompted, enter your username/password.

if the login is successfull you have logged in to the UNIX box.

The only role that telnet plays here is as a interface between you (client) and the UNIX box (server).

Telnet will not help you with anything other than that (eg. trying to locate a file).

for that you will have to use the UNIX find command.

once you are at the UNIX prompt type the following command to find out where Sendmail.pm is located.

NOTE: remember, by using this command you are searching the ENTIRE UNIX box for a file, so this process will take a some time to finish and also take up valuable server resources, so proceed with caution.


find / -type f -name "Sendmail.pm" -print 2> /dev/null

the above would start searching from the root directory (/) of your UNIX  server for a file (type -f) with the name Sendmail.pm (-name Sendmail.pm) and print out the results of the search (-print).

if there are any errors, like you dont have read access to some directories, those error messages will not be shown to you (> /dev/null).

i feel the better and faster method would be to ask the web server host if they have Sendmail.pm installed and the location of the same.

let me know how it goes.


Avatar of GorGor1

ASKER

Adjusted points from 30 to 40
Avatar of GorGor1

ASKER

i ran the command and after i'd say a minute or so, no results came up.  Not even 'File not found' or anything.  I take it Sendmail.pm is not installed.  That sucks.  How can I do this portion of code without Sendmail.pm?

sub sendMail {
 
# Build the body of your message
my $body = <<HERE;

    $comment

HERE

# The closing HERE must be on a line all by itself, with no
# whitespace in front of or after it
#Send the message
my %mail = ( To      => $webEmail,
             From    => $webEmail,
             Subject => 'COMMENT sent via form',
             Message => $body );
sendmail(%mail) or die $Mail::Sendmail::error;
}

All of my cgi scripts use this subroutine for sending mail.  Do I NEED sendmail.pm to do this? It would probably take 2 months for our host to install the sendmail module for us.  Thanks!
ASKER CERTIFIED SOLUTION
Avatar of maneshr
maneshr

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of GorGor1

ASKER

WOW, that is ugly!!  I'll give it a try tomorrow and let you know how it goes.  I can already see a problem with sending long automatically generated e-mails that have to be formatted 'just so'.

A couple of real quick questions:

1)What does the '=@_' do?
2)To call sub sendMail, wouldn't I just pass the proper variables to the subroutine? Like this:

sendMail(
  $webEmail,
  $email,
  'Hi: long time no see',
  'Hi\n\n
  Buddy, its a long time since i heard from you\n\n

  your pal\n'
);

Would that work?  Thanks again!
"...1)What does the '=@_' do? .."

@_ is a special PERL array that has all the incoming parameters in it.

by saying my($...)=@_;

i am saying, put every element of that special array into a seperate scalar variable.


"...2)To call sub sendMail, wouldn't I just pass the proper variables to the subroutine? Like this: ...

Would that work?...
"

yes that is right.
Avatar of GorGor1

ASKER

you're the man!  I'll do it up tomorrow and hand over the points if all goes well.  :o)
sure, sounds good.

wish you the very best.
Avatar of GorGor1

ASKER

hmmm...Everything works fine except the body of the e-mail is not showing up in the e-mail.  Do you see anything wrong here??

sub sendTheEmail {  ## Call the sendMail subroutine and pass it the proper variables
sendMail(
$webEmail,
$webEmail,
'COMMENT sent via form at ATTC web',
$comment);
}

sub sendMail{   ## subroutine that send the Email
my($to,$from,$subject,$body)=@_;

my $mailprog ="/usr/lib/sendmail";

open(MAIL, "| $mailprog -t ") || die $!;
print MAIL "To: $to\n";
print MAIL "From: $from\n";
print MAIL "Subject: $subject\n";
print MAIL "Body: $body\n";
close(MAIL);
return 0;
}

--------
I also tried it with the above line the way maneshr had it originally and it didn't work either:

'print MAIL $body;' instead of 'print MAIL "Body: $body\n";'

Neither of them worked. Any ideas?

Avatar of ozo
print MAIL "Subject: $subject\n";
print MAIL "\n$body";
you need to add an extra \n to the end of the following line..

CHANGE....

print MAIL "Subject: $subject\n";

TO....

print MAIL "Subject: $subject\n\n";

Avatar of GorGor1

ASKER

works like a charm now...thanks!