Sending Email to Multiple Recipients

I moved the old code from the old unix window to the new unix box, and I had difficulty sending perl script messages to multiple recipients. He works on an old box.

Old perl box: version 5.004_04 created for PA-RISC2.0

New perl box: v5.8.8 for IA64.ARCHREV_0-thread-multi-LP64

Here's the basics of the script (stripped down):

use Net::SMTP::Multipart;
$to = "sam\@bogus.com tom\@foo.com";
$smtp = Net::SMTP::Multipart->new($smtpserver);
$smtp->Header(To    =>  $to,
      From  =>  "junk\@junk.com",
      Subj  =>  "This is a test.");
$smtp->Text("Hello, world!\n");
$smtp->End();

This works if I change it to $to = "justOneEmail\@address.com", but if I have two or more email addresses (separated by spaces), it no longer works. I do not receive an error message, but the message does not appear.

Any ideas why?

+3
source share
3 answers

Do it like this :

use Net::SMTP::Multipart;
$to1 = "sam\@bogus.com"; 
$to2 = 'tom@foo.com';
$smtp = Net::SMTP::Multipart->new($smtpserver);
$smtp->Header(To    =>  [ $to1, $to2, 'another_email@server.com' ],
              From  =>  "junk\@junk.com",
              Subj  =>  "This is a test.");
$smtp->Text("Hello, world!\n");
$smtp->End();

, , @ , perl .

+2

. ..

+2

Declare an array and put all email id like

@MailTo = ('mail1@demomail.com', 'mail2@demomail.com', ...., 'mailn@demomail.com')

Now use the module Net::SMTPto send letters

$smtp->to(@MailTo);
-2
source

All Articles