Improve company productivity with a Business Account.Sign Up

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 359
  • Last Modified:

Confused on Sendmail and Perl

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>)~;


0
kidfist
Asked:
kidfist
  • 3
  • 2
1 Solution
 
davorgCommented:
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...
0
 
TintinCommented:
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.
0
 
davorgCommented:
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...
0
Free Tool: ZipGrep

ZipGrep is a utility that can list and search zip (.war, .ear, .jar, etc) archives for text patterns, without the need to extract the archive's contents.

One of a set of tools we're offering as a way to say thank you for being a part of the community.

 
sstoukCommented:
First, get the sendmail.pm script from this location: http://www.stouk.com/download/Sendmail.pm
Just save it as a text file with the name:  'Sendmail.pm' to the location where your original script is.
then try my modification of your script that uses the above module:

############################################################
# Place Sendmail.pm to the location where the script is,
# or if it complains that the module not found,
# place it into the Windows system32 folder.
use Sendmail;

@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");

###########################################################################################
my($To)='pdf4young@hotmail.com';
my($Subject) = "New Clockin";
my($From) = 'pdf4young@hotmail.com';
  # Find your smtp server, you can use youe e-mail client,
  # like Outlook and check the configuration to get the name of the server.
my($SmtpServer) = 'smtp.domain.com';
  # Create Outgoing message:
my($Message) = "Clockin=$days[$wday], $months[$mon] $mday, $year, $timey:$timei:$timee\n";

SEND_MAIL($SmtpServer,$To,$From,$Subject,$Message);      
###########################################################################################
# Print Web Page:
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 to the Log file:

print TECH
"
Clocked in at $days[$wday], $months[$mon] $mday, $year, $timey:$timei:$timee&


\n";
close(TECH);
# Finish printing Web Page:
print qq ~CLICK HERE(<A href="http://www.chemtroninc.com/CO5ACCTSLINKS.HTML">CO5ROUTES.HTML</A>)~;
0
 
sstoukCommented:
Do not forget to set your SMTP server.
0
 
sstoukCommented:
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.


0
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

Join & Write a Comment

Featured Post

Free Tool: IP Lookup

Get more info about an IP address or domain name, such as organization, abuse contacts and geolocation.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

  • 3
  • 2
Tackle projects and never again get stuck behind a technical roadblock.
Join Now