Solved

Confused and lost on Sendmail and Perl

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

How to improve team productivity

Quip adds documents, spreadsheets, and tasklists to your Slack experience
- Elevate ideas to Quip docs
- Share Quip docs in Slack
- Get notified of changes to your docs
- Available on iOS/Android/Desktop/Web
- Online/Offline

Join & Write a Comment

Ever wondered how to display how many visitors you have online. In this tutorial I will show you an easy but effective way to display the number of online visitors in WhizBase. In this article I assume you have read my previous articles and know …
In this tutorial I will show you how to make a simple HTML bar chart with the usage of WhizBase, If you want more information about WhizBase please read my previous articles at http://www.experts-exchange.com/ARTH_5123186.html (http://www.experts-ex…
Learn the basics of if, else, and elif statements in Python 2.7. Use "if" statements to test a specified condition.: The structure of an if statement is as follows: (CODE) Use "else" statements to allow the execution of an alternative, if the …
The viewer will learn how to look for a specific file type in a local or remote server directory using PHP.

707 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

15 Experts available now in Live!

Get 1:1 Help Now