Code Comments

Programming Forum and web based access to our favorite programming groups.
For Programmers: Free Programming Magazines | New: Database administration forum
Registration is free! Edit your profileCalendarFind other membersFrequently Asked QuestionsSearch -> 
Post New Thread











Thread
Author

Help with Sending Multiple Emails!
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

Report this thread to moderator Post Follow-up to this message
Old Post
Terry
10-06-04 08:56 PM


Re: Help with Sending Multiple Emails!
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

Report this thread to moderator Post Follow-up to this message
Old Post
Mike
10-08-04 01:55 AM


Re: Help with Sending Multiple Emails!
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



Report this thread to moderator Post Follow-up to this message
Old Post
G. Harrison Chiles Jr.
01-14-06 12:55 PM


Sponsored Links




Last Thread Next Thread Next
Search this forum -> 
Post New Thread

PERL Programming archive

Show a Printable Version Send to friend Email This Page to Someone! subscribe to this thread Receive updates to this thread
Computer Consultants
Programming Jobs
Visual Basic Controls
SQL Server Programming
Webservices
Java Security
Visual Studio
C# Programming
Visual J++
Software engineering
Open source Software
Perl Programming
PHP Programming
ASP Programming
ASP .NET Programming
Visual Basic Programming
Windows Scripting Host
Java Programming
Java Help
Java Beans
VBScript
Cobol
MAC Applications
Unix Programming
Forum Jump:
All times are GMT. The time now is 05:49 PM.

 
Free MCSE Braindumps | Real Estate Topics

Programming forum archive

Copyrights CodeComments.com 2004 - 2006

Powered by vBulletin Copyright 2000-2006 Jelsoft Enterprises Limited.