SPUG: sendmail from Perl (quick newbie question)

Peter Darley pdarley at kinesis-cem.com
Wed Feb 13 09:07:01 CST 2002


Jason,
	This doesn't answer your question in any way, but have you looked at any of
the email modules on CPAN?  The Mail::Sendmail module is simple, fast, and
easy to use, unless you're sending attachments.  If you're sending
attachments Mail::Sender is a good choice, tho it seems to be significantly
slower than Mail::Sendmail.  Both of these will accept addresses separated
by comas.
Thanks,
Peter Darley

-----Original Message-----
From: owner-spug-list at pm.org [mailto:owner-spug-list at pm.org]On Behalf Of
dancerboy
Sent: Tuesday, February 12, 2002 4:00 PM
To: Seattle Perl Users Group
Subject: SPUG: sendmail from Perl (quick newbie question)


Okay, this is more of a sendmail question than a Perl question, but I
figure there are many on this list who will be able to answer it in
10 seconds flat, whereas it would take me considerable amounts of
digging to find the answer in an "appropriate" forums...

How do you send to multiple addresses using sendmail?  I've got a
super-simple form-to-email CGI that accesses sendmail like this:


     sub send_mail {
         my $mailprog = '/usr/lib/sendmail';
         my (
             $to_addy,
             $from_addy,
             $from_realname,
             $subject,
             $msg_body
         ) = @_;

         ####  [ ... verifications omitted here for brevity ... ]

         open(MAIL,"|$mailprog -t") || die "Couldn't open |$mailprog -t: !";
             # Open The Mail Program

         (print MAIL "To: $to_addy\n")
             || die "Couldn't print to |$mailprog -t: $!";
         (print MAIL "From: $from_addy ($from_realname)\n")
             || die "Couldn't print to |$mailprog -t: $!";
         (print MAIL "Subject: $subject\n\n")
             || die "Couldn't print to |$mailprog -t: $!";
         (print MAIL "$msg_body\n")
             || die "Couldn't print to |$mailprog -t: $!";

         close (MAIL) || die "Error closing $mailprog: $!";
     }


I now need to modify the form so that it sends copies of the message
to multiple addresses.  I had thought that just putting multiple
addresses on the "To:" line, separated by commas, would do the trick,
but it doesn't:  when I set $to_addy to something like
'test_address_1 at myserver.com, test_address_2 at myserver.com,
test_address_3 at myserver.com' the message gets sent only to the first
address in the list (test_address_1 at myserver.com) not to any of the
others.

What's the correct syntax for sending to more than one address?

Thanks.

-jason

 - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
     POST TO: spug-list at pm.org       PROBLEMS: owner-spug-list at pm.org
      Subscriptions; Email to majordomo at pm.org:  ACTION  LIST  EMAIL
  Replace ACTION by subscribe or unsubscribe, EMAIL by your Email-address
 For daily traffic, use spug-list for LIST ;  for weekly, spug-list-digest
     Seattle Perl Users Group (SPUG) Home Page: http://seattleperl.org



 - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
     POST TO: spug-list at pm.org       PROBLEMS: owner-spug-list at pm.org
      Subscriptions; Email to majordomo at pm.org:  ACTION  LIST  EMAIL
  Replace ACTION by subscribe or unsubscribe, EMAIL by your Email-address
 For daily traffic, use spug-list for LIST ;  for weekly, spug-list-digest
     Seattle Perl Users Group (SPUG) Home Page: http://seattleperl.org





More information about the spug-list mailing list