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
Solved

Confused and lost on Sendmail and Perl

Posted on 2004-03-25
5
290 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

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.

Question has a verified solution.

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

Suggested Solutions

In this tutorial I will aim to show you how simple is making a small application in WhizBase, how to add, remove and update data in the DB. I will make a small address book application where you can add, browse, update and remove addresses. I wi…
It is a general practice to get rid of old user profiles on a computer  in a LAN environment. As I have been working with a company in a LAN environment where users move from one place to some other place at times. This will make many user profil…
The viewer will learn how to dynamically set the form action using jQuery.
This tutorial will teach you the core code needed to finalize the addition of a watermark to your image. The viewer will use a small PHP class to learn and create a watermark.

809 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