in reply to sending to multiple recipients with Net::SMTP

The to() method can take a list of addresses. So don't try to put multiple addresses into one string, just pass them in as separate strings:

$smtp->to($address1, $address2, ... );
or
@addrs = ("me\@testserver.com","someone\@elsewhere.com"); $smtp->to(@addrs);

I think you can also do $smtp->to(...) multiple times, for the same effect, but I could be remembering that wrong.

Oh, and don't forget to escape the @ in a double-quoted string...


s^^unp(;75N=&9I<V@`ack(u,^;s|\(.+\`|"$`$'\"$&\"\)"|ee;/m.+h/&&print$&

Replies are listed 'Best First'.
Re^2: sending to multiple recipients with Net::SMTP
by nimdokk (Vicar) on Nov 08, 2004 at 13:45 UTC
    You can do $smtp->to(...) multiple times. This is how we have it set up:

    @email=qw(address1@host1.com address2@host2.com address3@host3.com); $smtp->new('my.mailhost'); $smtp->mail('myaddress@myhost.com'); foreach (<@email>) { $smtp->to($_); } $smtp->datasend("Rule 42 is now in effect.\n"); $smtp->dataend; $smtp->quit;
    Perhaps not the cleanest, but it works quite nicely.

    Update: forgot the $smtp->quit;. Also removed commas from @email=qw(...) per comment below.

      Thanks for confirming that.

      Just for the sake of pedantry, you have commas in your qw() which shouldn't be there. Perl will warn you about this if you have warnings turned on.


      s^^unp(;75N=&9I<V@`ack(u,^;s|\(.+\`|"$`$'\"$&\"\)"|ee;/m.+h/&&print$&
        Thanks, I couldn't remember if the commas would have been in there or not, I don't normally set array's like that.
Re^2: sending to multiple recipients with Net::SMTP
by Anonymous Monk on Nov 08, 2004 at 13:48 UTC
    Hi muntfish,

    Thanks for your quick reply, you got it dead right, everything working now. ++

    Thanks a lot,
    Jonathan.