We help IT Professionals succeed at work.

Confused on Sendmail and Perl

kidfist
kidfist asked
on
Medium Priority
371 Views
Last Modified: 2010-03-04
Hello,

I am very new at this and trying to work with books for making PERL scripts. I am trying to get a script to write to a text file and send and e-mail. I can get the script to write to a text file.  However I cannot get the perl script to send an email.  I was using sendmail. Then I later found out That was for unix only and not windows. So now what? If Sendmail is for unix only then what do I do? Could someone look at my code and give me a hand. This is job related so it is important.

@gold=split(/&/,$buffer);
foreach $ab (@gold) {
($le,$ri)=split(/=/,$ab);
$ri=~tr/+/ /;
$ri=~s/%([a-fA-F0-9][a-fA-F0-9])/pack("C",hex($1))/eg;
$Regis{$le}=$ri;
}
open(TECH,">>./TEXTFILES/CO5ACCTS.txt");
open(MAIL, "|/usr/lib/sendmail -oi -t ")|| die "Cannot start sendmail: $!\n";

$email='pdf4young@hotmail.com';


print MAIL "To: $email \n";
print MAIL "Subject: New Clockin\n";
print MAIL "Clockin=$days[$wday], $months[$mon] $mday, $year, $timey:$timei:$timee\n";

close MAIL or die $!;
print "Content-type: text/html\n\n";
@days = ("Sunday","Monday","Tuesday","Wednesday","Thursday",

"Friday","Saturday");
@months = ("January","February","March","April","May","June",

"July","August","September","October","November", "December");


@days = ("Sunday","Monday","Tuesday","Wednesday","Thursday",
        "Friday","Saturday");
@months = ("January","February","March","April","May","June",
          "July","August","September","October","November",
          "December");
($sec,$min,$hr,$mday,$mon,$year,$wday,$yday,$isdst) =
localtime(time);
$year = $year + 1900;
$timey=$hr;
$timei=$min;
$timee=$sec;
print TECH
"
Clocked in at $days[$wday], $months[$mon] $mday, $year, $timey:$timei:$timee&


\n";
close(TECH);
print qq ~CLICK HERE(<A href="http://www.chemtroninc.com/CO5ACCTSLINKS.HTML">CO5ROUTES.HTML</A>)~;


Comment
Watch Question

Dave CrossPerl programmer, author and trainer
CERTIFIED EXPERT

Commented:
You have a couple of options.

1/ Find a Windows program that emulates sendmail. I believe that many people use one called "blat".

2/ Use the Net::SMTP module to talk directly to your SMTP server.

Dave...
CERTIFIED EXPERT
Top Expert 2007

Commented:
davorg.

It is a common misbelief that blat is equivalent to sendmail.  Not so, blat is a MUA (Mail User Agent) and sendmail is a MTA (Mail Transport Agent).

Apart from using Net::SMTP, you're probably better off using one of the higher level modules for mail such as Mail::Sendmail (which, despite the name, will talk SMTP)

Some general comments on your script.

1.  Use the standard CGI module for parsing CGI parameters.
2.  Always check the result of opening files.
3.  The POSIX strftime will simplify all your arrays and date code into one line.
Dave CrossPerl programmer, author and trainer
CERTIFIED EXPERT

Commented:
It don't know enough about Windows software to comment on this,  but I understand that you can use blat in place of sendmail in things like formmail scripts. I'm pretty sure that I've seen it done. Is that not the case?

Dave...
Unlock this solution and get a sample of our free trial.
(No credit card required)
UNLOCK SOLUTION
Do not forget to set your SMTP server.
Basically to send an e-mail from Windows using Perl is not that complicated.
There are multiple solutions developed already.
Starting from a simple Sendmail.pm module, which does not send attachments (although it is possible to encode attachment in the outgoing e-mail before using Sendmail and send it);
You can use a standard Net::SMTP module to send away simple messages and this options is standard with ActiveState installation of Perl - check your ActiveState Documentation for sending e-mail example;
However my best so far is MIME::Lite.
It is not difficult to install this module and it provides the easiest way of handling e-mails WITH attachments and multiple e-mail options.
You can build your own fully functional multy-user e-mail client with it, and this is exactly what i did a few months ago.
All my utilities I built for work come standard with e-mail alert notification options.

From the above example you can see that there are two critical lines, needed to send an e-mail message:
"use Sendmail;"
and
"SEND_MAIL($SmtpServer,$To,$From,$Subject,$Message);"

Hope this helps.


Unlock the solution to this question.
Thanks for using Experts Exchange.

Please provide your email to receive a sample view!

*This site is protected by reCAPTCHA and the Google Privacy Policy and Terms of Service apply.

OR

Please enter a first name

Please enter a last name

8+ characters (letters, numbers, and a symbol)

By clicking, you agree to the Terms of Use and Privacy Policy.