cacharbe has asked for the wisdom of the Perl Monks concerning the following question:

I am sending mail to an email list that I manage and I recently went from using NET::SMTP to MIME::Lite (Members requested teh ability to include formatted code, etc). Using ::SMTP, I could pass the smtp server an array of addresses, and it would handle going through the list and sending the msg one at a time. With MIME::Lite, however, this doesn't appear to work, which requires me to loop through the addresses myself.

Can I use the same method with MIME::Lite - sending an array of addresses - and what do I have to do differently?

After reading through the MIME::Lite docs, I found no mention of this functionality, but that doesn't necessarily mean that it doesn't exist.

The two pieces of mail code are munged together and included below, for posterity. It doesn't represent the application, merely an example of what I am speaking.

use MIME::Lite; use Net::SMTP; my @addrlist = (<BIG ASS LIST OF ADDRS>); my $msg = "<A HUGE MSG, 100's of lines Long>"; &EMailSMTP(\@addrlist,\$msg) || die "Couldn't SMTP :$!\n"; &EMailMIME(\@addrlist,\$msg) || die "Couldn't MIME :$!\n"; sub EMailSMTP { my ($addrs, $Lusertxt) = @_; @headers = ("Subject: Subject Text.\n", "To : To Mask \n", "From : me\@here.com\n", "\n", "$$Lusertxt\n"); my $smtp = Net::SMTP->new('mailserver.com') || die "Nope!! No SMTP +:$!\n"; $smtp->mail("fromaddr\@here.com"); $smtp->to(@$addrs); $smtp->data(@headers) ; $smtp->quit; return 1; } sub EMailMIME{ my ($addrs, $Lusertxt) = @_; MIME::Lite->send('smtp', "mailserver.com", Timeout=>60); foreach my $addr (@$addrs){ my $msg = MIME::Lite->new( From =>'someaddr@here.com', To =>$addr, Subject =>"Subject Text", Type =>'TEXT', Data => $$Lusertxt ); $msg->send(); } return 1; }

FYI: This is on a Win2k Advanced Server Machine, using AS Perl, and SMTP services from our corporate mail server.

Replies are listed 'Best First'.
Re: Sending msgs with MIME::Lite vs NET::SMTP to a list of addrs
by chromatic (Archbishop) on Sep 20, 2001 at 05:18 UTC
    Looking at the MIME::Lite documentation, it seems you can pass an array reference to the add() method. Otherwise, you might follow the doc example for the Cc field:
    my $msg = MIME::Lite->new( From => 'someaddr@here.com', To => join(',', @$addrs), Subject => 'Subject Text', Type => 'TEXT', Data => $$Lusertxt, );
    Your mileage may vary. I don't have it installed, and I'm super lazy, but at least you got a response. :)
      A HA!!! Missed that reference.

      Thank you.

      C-.