Help with Sending Multiple Emails!

Help with Sending Multiple Emails!

am 06.10.2004 20:55:57 von Terry

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

Re: Help with Sending Multiple Emails!

am 07.10.2004 23:30:10 von Mike

Terry,

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

Re: Help with Sending Multiple Emails!

am 14.01.2006 05:52:32 von gharrison64

put 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" 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