Solved

Confused and lost on Sendmail and Perl

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

Announcing the Most Valuable Experts of 2016

MVEs are more concerned with the satisfaction of those they help than with the considerable points they can earn. They are the types of people you feel privileged to call colleagues. Join us in honoring this amazing group of Experts.

Question has a verified solution.

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

Introduction This tutorial will give you a fast look what you can do with WhizBase. I expect you already know how to work with HTML at least, and that you understand the basics of the internet and how the internet works. WhizBase is a server-s…
A quick Powershell script I wrote to find old program installations and check versions of a specific file across the network.
Learn how to match and substitute tagged data using PHP regular expressions. Demonstrated on Windows 7, but also applies to other operating systems. Demonstrated technique applies to PHP (all versions) and Firefox, but very similar techniques will w…
The viewer will learn how to count occurrences of each item in an array.

738 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