Solved

Confused and lost on Sendmail and Perl

Posted on 2004-03-25
5
291 Views
Last Modified: 2013-12-25
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
5 Comments
 
LVL 3

Expert Comment

by:rkosai
ID: 10680421
Sending E-mail under Windows is easy if you use a Perl module called Mail::Sender.  The documentation for this is available at: http://search.cpan.org/~jenda/Mail-Sender-0.8.10/Sender.pm

I've used code like this several times; and it works great.

Using the module, the code is as easy as:
#!/usr/bin/perl
use Mail::Sender;
MailMsg({from => "somebody@somewhere.com", to => "else@nowhere.com", msg => "Message"});
0
 
LVL 3

Expert Comment

by:rkosai
ID: 10680502
Alright; I made a mistake in the sample code noted above.  I obviously didn't quite remember how to use it.   Here is an actual use of mail sender in action, with code that I know works:

#!/usr/bin/perl

use Mail::Sender;
my $mailmessage = ''This is my message";

my $sender = new Mail::Sender {
  smtp => 'your.smtp.server',
  from => 'sender@sender.com',
  to => 'destination@destination.com',
  subject => 'My Subject',
  on_errors => undef
  } or die "Can't create the Mail::Sender object: $Mail::Sender::Error\n";

$sender->MailMsg({msg => $mailmessage});
$sender->Close() or die "Failed to send the message: $sender->{'error_msg'}\n";
0
 
LVL 48

Expert Comment

by:Tintin
ID: 10683675
Did you mean to create a duplicate question?  If not, put a request in to close one of them.
0
 

Author Comment

by:kidfist
ID: 10694288
#!/usr/bin/perl
Thanks for the help guys but could someone please  explain what each one of these linbes means. I have no idea
What do these 2 lines mean
my $mailmessage = ''This is my message";
smtp => 'your.smtp.server',

use Mail::Sender;
my $mailmessage = ''This is my message";

my $sender = new Mail::Sender {
  smtp => 'your.smtp.server',
  from => 'sender@sender.com',
  to => 'destination@destination.com',
  subject => 'My Subject',
  on_errors => undef
  } or die "Can't create the Mail::Sender object: $Mail::Sender::Error\n";

$sender->MailMsg({msg => $mailmessage});
$sender->Close() or die "Failed to send the message: $sender->{'error_msg'}\n";
0
 
LVL 3

Accepted Solution

by:
rkosai earned 500 total points
ID: 10695844
Some notes about the script as posted:

my $mailmessage = ''This is my message";
This is the mail message that you want to send out.  "my" declares the variable to be local to the script.  $mailmessage is a variable that stores the message that goes into the "body" of your e-mail.

smtp => 'your.smtp.server'
'your.smtp.server' is whatever SMTP server you use to send outgoing mail.  They usually come as part of your ISP.  Since this is work-related as you indicated, you should be able to use your corporate mail server for outgoing e-mails.
0

Featured Post

Resolve Critical IT Incidents Fast

If your data, services or processes become compromised, your organization can suffer damage in just minutes and how fast you communicate during a major IT incident is everything. Learn how to immediately identify incidents & best practices to resolve them quickly and effectively.

Question has a verified solution.

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

Introduction:   Welcome to my first article ever. To begin with, the reason I write this article.  I participated in a question on Experts Exchange about the start command in Windows and there were some discussion about the usage. The discussio…
The Windows functions GetTickCount and timeGetTime retrieve the number of milliseconds since the system was started. However, the value is stored in a DWORD, which means that it wraps around to zero every 49.7 days. This article shows how to solve t…
Learn the basics of while and for loops in Python.  while loops are used for testing while, or until, a condition is met: The structure of a while loop is as follows:     while <condition>:         do something         repeate: The break statement m…
In this seventh video of the Xpdf series, we discuss and demonstrate the PDFfonts utility, which lists all the fonts used in a PDF file. It does this via a command line interface, making it suitable for use in programs, scripts, batch files — any pl…

756 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