On Thursday 10 Mar 2005 20:28, Wiggins d'Anconia wrote: > Gavin Henry wrote: > > Dear all, > > > > I have the following: > > > > #!/usr/bin/perl > > use strict; > > use warnings; > > use Mail::Sendmail; > > > > my $from = '"Test e-mails" <[EMAIL PROTECTED]>'; > > my $subject = 'Testing for survey e-mail'; > > > > open LIST, "<mailinglist" > > or die "Cannot open mailing list: $!"; > > > > open MESSAGE, "<mailinglist-message" > > or die "Cannot open mailing list message: $!"; > > > > my $message = <MESSAGE>; > > > > foreach (<LIST>) { > > my %mails = ( > > To => "$_", > > From => "$from", > > Subject => "$subject", > > Message => "$message", > > ); > > For efficiency you can most of the hash outside of the loop and then > just tack on the To address inside of the loop since it is the only > thing that changes. You can use slurp mode as the other poster mentioned > or you can join the lines to turn them into a single string. > > > sendmail(%mails) or die $Mail::Sendmail::error; > > > > print "Message has been sent to $_"; > > }; > > > > close LIST; > > close MESSAGE; > > print "All e-mails sent successfully.\n\n"; > > > > > > 1. How can I get my whole email message into Message => > > 2. I think my filehanldes are messess, can you suggest anything? > > 3. my $message = <MESSAGE>; only gives the first line? > > > > Thanks, > > > > G. > > my @message = <MESSAGE>; > > my %mails = ( > From => "$from", > Subject => "$subject", > Message => join "", @message, > ); > > foreach (<LIST>) { > sendmail('To' => $_, %mails) or die $Mail::Sendmail::error; > print "Message has been sent to $_"; > }; > > perldoc -f join
Excellent, many thanks. I remember reading that the other day. > > Also note this can be somewhat dangerous since you will die anytime a > message fails to send. The problem is, what if you have 10 messages and > message 3 fails? 4-10 don't get sent, the problem is that 1-2 have been > sent. You might capture all failures to a list of failed addresses, > etc. warning on each pass. Then print some sort of good/bad report so > you know which ones need to be resent. As you can tell this problem > gets magnified very quickly as the number of addresses in your list goes > up. Wouldn't sendmail just have them in a queue, and I would get I message later on? What if I changed die, to warn in: or die $Mail::Sendmail::error; and stuck that in a file? -- Just getting into the best language ever... Fancy a [EMAIL PROTECTED] or something on http://www.perl.me.uk Just ask!!! -- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED] <http://learn.perl.org/> <http://learn.perl.org/first-response>