Solved

Confused on Sendmail and Perl

Posted on 2004-03-25
6
343 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
  • 3
  • 2
6 Comments
 
LVL 8

Expert Comment

by:davorg
Comment Utility
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
Comment Utility
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
Comment Utility
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
Top 6 Sources for Identifying Threat Actor TTPs

Understanding your enemy is essential. These six sources will help you identify the most popular threat actor tactics, techniques, and procedures (TTPs).

 
LVL 6

Accepted Solution

by:
sstouk earned 500 total points
Comment Utility
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
Comment Utility
Do not forget to set your SMTP server.
0
 
LVL 6

Expert Comment

by:sstouk
Comment Utility
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

Threat Intelligence Starter Resources

Integrating threat intelligence can be challenging, and not all companies are ready. These resources can help you build awareness and prepare for defense.

Join & Write a Comment

Suggested Solutions

I have been pestered over the years to produce and distribute regular data extracts, and often the request have explicitly requested the data be emailed as an Excel attachement; specifically Excel, as it appears: CSV files confuse (no Red or Green h…
A year or so back I was asked to have a play with MongoDB; within half an hour I had downloaded (http://www.mongodb.org/downloads),  installed and started the daemon, and had a console window open. After an hour or two of playing at the command …
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…
Internet Business Fax to Email Made Easy - With eFax Corporate (http://www.enterprise.efax.com), you'll receive a dedicated online fax number, which is used the same way as a typical analog fax number. You'll receive secure faxes in your email, fr…

728 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

Need Help in Real-Time?

Connect with top rated Experts

9 Experts available now in Live!

Get 1:1 Help Now