mlebel has asked for the wisdom of the Perl Monks concerning the following question:
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!
|
---|
Back to
Seekers of Perl Wisdom