Beefy Boxes and Bandwidth Generously Provided by pair Networks
XP is just a number
 
PerlMonks  

Mail::Sender Distribution List

by cocl04 (Sexton)
on Oct 08, 2009 at 14:22 UTC ( [id://799978]=perlquestion: print w/replies, xml ) Need Help??

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

All, I am trying to pass a list of email addresses from an array to Mail::Sender. I have tried putting comma between them, single quotes at the end, double quotes at the end and nothing. I can't seem to get it to work. I have dumped the data via DATA::DUMPER and it is fine. I can print the data and it is fine. I have an old project where I send an array of attachement. And it works fine. But the To => syntax does not seem ot work the same. Does anyone have any ideas? The data is in an the array @rd_list. I have also tried \@rd_list which worked for the array of attachements.

$sender->MailFile( { to => @rd_list, subject => 'Test', msg => "All, Please ignore this email! This is a test. Thanks, cc\n", file => $complete_file_path, }); $sender->Close;

Replies are listed 'Best First'.
Re: Mail::Sender Distribution List
by jethro (Monsignor) on Oct 08, 2009 at 14:53 UTC
    The documentation of Mail::Sender tells us:

    to => the recipient's address(es) This parameter may be either a comma separated list of email + addresses or a reference to a list of addresses.
    This and the examples later in the docu indicate that it should work like this:

    to => join(',',@rd_list);
    The documentation talks about a list, but the term 'comma separated' gives a hint that it actually wants a single string with comma separated values!

    Your example above is definitely false because @rd_list would be expanded to parameters. If you remember that '=>' is just an alias for ',' and each value in @rd_list will be just another parameter, you get the following:

    @rd_list= ('a@b.com','b@b.com', 'c@c.com'); #Your example is then equivalent to: $sender->MailFile( { 'to', 'a@b.com', 'b@b.com', 'c@c.com' 'subject', 'Test', 'msg', "All, ...
    In your example the method MailFile can't recognize whether 'subject' is still an email address or already another header. Actually '\@rd_list' would have been quite sensible and could have worked
Re: Mail::Sender Distribution List
by roboticus (Chancellor) on Oct 08, 2009 at 14:56 UTC
    cocl04:

    Check the examples. The second one sends mail to two addresses.

    ...roboticus

      I figured it out. None of the array syntax worked. So, I converted the data in the array into a comma delimited string and put double quotes at the beginning and end of the string and it worked. The double quotes are added by the sql and are apart of the string. I used this implementation because my process reads in about 70 plus email addresses from the data set I need. I load those email addresses into an array. Hard coding them would not be good because they might change. By selecting them from my final data set, I ensure I have the most up to date list. Thanks!!!

      my $rd_string = join('',@rd_list);
Re: Mail::Sender Distribution List
by hominid (Priest) on Oct 08, 2009 at 14:49 UTC
    I use a comma separated list, not an array.
    my $rd_list = 'a@a.com, b@b.com, etc@etc.com'; $sender->MailFile( { to => $rd_list, subject => 'Test', msg => "All, Please ignore this email! This is a test. Thanks, cc\n", file => $complete_file_path, });

Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: perlquestion [id://799978]
Approved by toolic
help
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others having an uproarious good time at the Monastery: (4)
As of 2024-04-19 03:04 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found