Gossamer Forum
Home : General : Perl Programming :

sending mail using perl

Quote Reply
sending mail using perl
Hi everyone. Am really new in here.

Have a lil' qn here. I need to send a email in my perl scripting..but... i am running this perll script in windows not unix environment.

Can anyone help me with this? as mail function is not recognised in my windows.. they keep referring as c:/perl/lib.... not found.

THanks in ADVANCE!! Wink
Quote Reply
Re: [sammy1] sending mail using perl In reply to
http://mysite.directlink.net/gbarr/pod/Net/SMTP.html

That is the easiest way.
Quote Reply
Re: [Paul] sending mail using perl In reply to
but..@ the start of my script already have pblm cos' they can't recognise "use Net::SMTP;" they can't find the path. so any soln?
Quote Reply
Re: [sammy1] sending mail using perl In reply to
Install it :)

ppm install Net::SMTP
Quote Reply
Re: [Paul] sending mail using perl In reply to
I'm having a related problem. Here's the code:

Code:
87 my $mailer = "/usr/lib/sendmail -i -t";
88 open(MAIL,"|$mailer");
89 print MAIL "To: $to_address\n";
90 print MAIL "From: $from_address\n";
91 print MAIL "Subject: $subject\n\n";
92 print MAIL "$body\n";
93 close (MAIL);

Which only works if I don't use the -T switch; otherwise I get Insecure $ENV{PATH} while running with -T switch at ... line 88.

How do I untaint this?
Quote Reply
Re: [SandyM] sending mail using perl In reply to
Firstly you should add something like:

open( ... ) or die "Can't init sendmail: $!";

....to make sure sendmail loads ok.

But in answer to your question you can fix the tainting error by specifying the PATH variable within your script....eg....

$ENV{PATH} = "/bin:/usr/bin";
Quote Reply
Re: [Paul] sending mail using perl In reply to
Frown

I've tried setting the PATH variable in the script, but I get a runtime error no matter what I try. I don't actually understand how to set the PATH, so I ran $print "$ENV{PATH};" to see what the PATH was, and then pasted this output into the mailing script, figuring that if the information displayed is valid, then setting that should be ok. Alas, still a runtime error. I'm not even getting my display_error routine to give me any output here:
Code:
$ENV{PATH} = "/usr/sbin:/sbin:/usr/local/sbin:/usr/local/bin:/sbin:/bin:/usr/sbin:/usr/bin:/usr/X11R6/bin:/root/bin" or display_error("Set PATH failed");

So, given that I can actually run the above line in another test stub of a program, I've figured out that the problem arises due to some conflict with
Code:
my $mailer = '/usr/lib/sendmail'
, and that this usr/lib/ needs to be added to ENV{PATH}... does it?

How exactly is this done, or better still, where do I find the documentation that explains to me how to do this? I have a shelf full of O'Reilly books, and they're all keeping it to themselves.
Quote Reply
Re: [SandyM] sending mail using perl In reply to
You won't get:

or display_error("Set PATH failed")

...to execute as $ENV{PATH} is always going to be defined as you are setting it manually so the "or" will never run. It would only have a chance of executing if you had something like:

$ENV{PATH} = $my_var or return display_error("set PATH failed");

....and $my_var happened to be empty.

You need to check your error log for the reason it is failing.
Quote Reply
Re: [Paul] sending mail using perl In reply to
Thanks for your help, Paul - particular the open(MAIL) or die construct, I would most likely have missed that out in my frustration over the PATH problem. (Which turned out to be resolved with
Code:
$ENV{PATH} = "/usr/lib";
inserted prior to the $mailer declaration, for anyone else ever getting stuck with this sort of thing.)