Code Comments
Programming Forum and web based access to our favorite programming groups.Hi, I am new to Perl. I ran into this problem while trying to send out 2 messages from a script. Nearly half the time, the second message didn't get sent, while the first message always get sent. Here is what I did: # send the 1st message open (M, "| /usr/sbin/sendmail -t"); print M "To: $address_01\n"; print M "From: $address_from\n"; .. # content of 1st message close (M); # send the 2nd message open (M, "| /usr/sbin/sendmail -t"); print M "To: $address_02\n"; print M "From: $address_from\n"; .. # content of 2nd message close (M); I wonder if this is the right way to implement this. Is there a way to check to see if the messages have been sent successfully? Thanks in advance for your help! Terry
Post Follow-up to this messageTerry,
Look into the module MIME::Lite it handles talking to the smtp server
and will die and give an error message if it fails.
A sample snippet:
use MIME::Lite;
use Net::SMTP;
my $pagetosend = 'your email body text';
my $msg = MIME::Lite->new (
From => 'from_address',
To => 'to_address',
Subject => 'subject',
Type => 'text/html',
Data=> $pagetosend
) or die "Error creating inline email $!\n";
print "Got the page, connecting to mail server\n";
### Send the Message
MIME::Lite->send('smtp', 'smtp.mail.host', Timeout=>60);
$msg->send or die "Error sending email to $mail_host: $!\n";
Terry wrote:
> Hi,
>
> I am new to Perl. I ran into this problem while trying to send out 2
> messages from a script. Nearly half the time, the second message didn't
> get sent, while the first message always get sent. Here is what I did:
>
> # send the 1st message
> open (M, "| /usr/sbin/sendmail -t");
>
> print M "To: $address_01\n";
> print M "From: $address_from\n";
> ...
> # content of 1st message
>
> close (M);
>
>
> # send the 2nd message
> open (M, "| /usr/sbin/sendmail -t");
>
> print M "To: $address_02\n";
> print M "From: $address_from\n";
> ...
> # content of 2nd message
>
> close (M);
>
>
> I wonder if this is the right way to implement this. Is there a way to
> check to see if the messages have been sent successfully?
>
> Thanks in advance for your help!
>
> Terry
Post Follow-up to this messageput you mail snippet in a subroutine and for each address pass it to the
subrountine.
Example
foreach $address (@addresses){
&sendmail($address)
}
#---------------------------------------
sub sendmail{
#---------------------------------------
($address_01) =@_;
open (M, "| /usr/sbin/sendmail -t");
$address_from="SomeEmailAddress";
print M "To: $address_01\n";
print M "From: $address_from\n";
..
# content of 1st message
close (M);
# send the 2nd message
open (M, "| /usr/sbin/sendmail -t");
print M "To: $address_02\n";
print M "From: $address_from\n";
..
# content of 2nd message
close (M);
}
"Terry" <gobeyondgobeyond@Rem0ve.Yahoo.com> wrote in message
news:MPG.1bcdfbb88557810c9896b4@news.tc.umn.edu...
> Hi,
>
> I am new to Perl. I ran into this problem while trying to send out 2
> messages from a script. Nearly half the time, the second message didn't
> get sent, while the first message always get sent. Here is what I did:
>
> # send the 1st message
> open (M, "| /usr/sbin/sendmail -t");
>
> print M "To: $address_01\n";
> print M "From: $address_from\n";
> ...
> # content of 1st message
>
> close (M);
>
>
> # send the 2nd message
> open (M, "| /usr/sbin/sendmail -t");
>
> print M "To: $address_02\n";
> print M "From: $address_from\n";
> ...
> # content of 2nd message
>
> close (M);
>
>
> I wonder if this is the right way to implement this. Is there a way to
> check to see if the messages have been sent successfully?
>
> Thanks in advance for your help!
>
> Terry
Post Follow-up to this message
Show a Printable Version
Email This Page to Someone!
Receive updates to this thread
Powered by vBulletin
Copyright 2000-2006 Jelsoft Enterprises Limited.