For Programmers: Free Programming Magazines  


Home > Archive > PERL Programming > January 2006 > Help with Sending Multiple Emails!









You are viewing an archived Text-only version of the thread. To view this thread in it's original format and/or if you want to reply to this thread please [click here]

 

Author Help with Sending Multiple Emails!
Terry

2004-10-06, 3:56 pm

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
Mike

2004-10-07, 8:55 pm

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

G. Harrison Chiles Jr.

2006-01-14, 7:55 am

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



Sponsored Links







Also available: Server administration forum archive | Web Design forum archive | Software forum archive | Hardware reviews archive

Copyright 2008 codecomments.com