Still celebrating National IT Professionals Day with 3 months of free Premium Membership. Use Code ITDAY17

x
?
Solved

Confused on Sendmail and Perl

Posted on 2004-03-25
6
Medium Priority
?
350 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>)~;


0
Comment
Question by:kidfist
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 3
  • 2
6 Comments
 
LVL 8

Expert Comment

by:davorg
ID: 10680167
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
 
LVL 48

Expert Comment

by:Tintin
ID: 10683653
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
 
LVL 8

Expert Comment

by:davorg
ID: 10684835
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
Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 
LVL 6

Accepted Solution

by:
sstouk earned 2000 total points
ID: 10696417
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
 
LVL 6

Expert Comment

by:sstouk
ID: 10696421
Do not forget to set your SMTP server.
0
 
LVL 6

Expert Comment

by:sstouk
ID: 10696447
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

Featured Post

Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Email validation in proper way is  very important validation required in any web pages. This code is self explainable except that Regular Expression which I used for pattern matching. I originally published as a thread on my website : http://www…
Checking the Alert Log in AWS RDS Oracle can be a pain through their user interface.  I made a script to download the Alert Log, look for errors, and email me the trace files.  In this article I'll describe what I did and share my script.
Explain concepts important to validation of email addresses with regular expressions. Applies to most languages/tools that uses regular expressions. Consider email address RFCs: Look at HTML5 form input element (with type=email) regex pattern: T…
Six Sigma Control Plans

705 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question