?
Solved

Confused and lost on Sendmail and Perl

Posted on 2004-03-25
5
Medium Priority
?
294 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
[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
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 2000 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

Get real performance insights from real users

Key features:
- Total Pages Views and Load times
- Top Pages Viewed and Load Times
- Real Time Site Page Build Performance
- Users’ Browser and Platform Performance
- Geographic User Breakdown
- And more

Question has a verified solution.

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

This article will show, step by step, how to integrate R code into a R Sweave document
Originally, this post was published on Monitis Blog, you can check it here . In business circles, we sometimes hear that today is the “age of the customer.” And so it is. Thanks to the enormous advances over the past few years in consumer techno…
In this fourth video of the Xpdf series, we discuss and demonstrate the PDFinfo utility, which retrieves the contents of a PDF's Info Dictionary, as well as some other information, including the page count. We show how to isolate the page count in a…
In a recent question (https://www.experts-exchange.com/questions/29004105/Run-AutoHotkey-script-directly-from-Notepad.html) here at Experts Exchange, a member asked how to run an AutoHotkey script (.AHK) directly from Notepad++ (aka NPP). This video…
Suggested Courses

801 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