Hello, I would like to get some help here with sending emails to multiple recipients using Mail::Sender. My code works ok when it sits within the same script. The problem crops up when I take the list of email addresses and Move them to another file. I don't get any errors and I don't receive the emails in any of the addresses inside the list. I have tried everything and cannot get it working.

Previous code is like so: (This is the working code)

#!/usr/bin/perl use Mail::Sender $To = 'email1@example1.com,email2@example2.com'; $sender = new Mail::Sender { smtp => 'smtp.mailserver.com', from => 'script@somedomain.com, }); $Subject = 'This is a Test Email'; $sender->OpenMultipart({ to => "$To", subject => "$Subject", }); $Sender->Body; $Sender->SendLineEnc("Test line 1"); $Sender->SendLineEnc("Test line 2"); $Sender->Attach({ description => 'Test file', ctype => 'application/pdf', encoding => 'Base64', disposition => 'attachment; filename="File.pdf"; type="PDF"', file => "$File", }); $sender->Close(); exit();

Current code is like so: (This is the non working code)

Here is the line that resides inside $TestFile:

To = mail1@example1.com,email2@example2.com

And now the Code:

#!/usr/bin/perl use Mail::Sender $TestFile = "../etc/TestFile.conf"; if (!open(TESTFILE,$TestFile)) { print "ERROR: Unable to open Test File for reading: $TestFile"; exit(); } foreach $Line (<TESTFILE>) { if ($Line =~ m/To\s*=\s*(.*)/) { $To = $1; print "To = <$To>\n"; } } $sender = new Mail::Sender { smtp => 'smtp.mailserver.com', from => 'script@somedomain.com, }); $Subject = 'This is a Test Email'; $sender->OpenMultipart({ to => "\'$To\'", subject => "$Subject", }); $Sender->Body; $Sender->SendLineEnc("Test line 1"); $Sender->SendLineEnc("Test line 2"); $Sender->Attach({ description => 'Test file', ctype => 'application/pdf', encoding => 'Base64', disposition => 'attachment; filename="File.pdf"; type="PDF"', file => "$File", }); $sender->Close(); exit();

Any help is greatly appreciated!


In reply to Sending Email to a list of people using Mail::Sender by mlebel

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.