Beefy Boxes and Bandwidth Generously Provided by pair Networks
more useful options
 
PerlMonks  

adding multiple attachments to email

by perlnoobster (Sexton)
on Apr 30, 2013 at 08:22 UTC ( #1031354=perlquestion: print w/replies, xml ) Need Help??
perlnoobster has asked for the wisdom of the Perl Monks concerning the following question:

Hi monks, I am unable to add multiple attachements to an email (i'm using the Mail::Sender module) here is my code:
send_email(); sub send_email { my $sender=new Mail::Sender({from =>$email_sender, fake_from =>$email_sender,smtp => 'mail.test.com'}); $sender->MailFile({to => $email_recipient, subject => $email_subject, file=> $outfile, file=> $file1, msg => $email_body}); }
only the first file (outfile) is attached to the email, the second file (file1) is not. please can someone help me? Thank you

Replies are listed 'Best First'.
Re: adding multiple attachments to email
by aitap (Deacon) on Apr 30, 2013 at 08:49 UTC

    Parameters of MailFile method are constructed from a hash, which is a "unique key" -> "some value" map. There can be only one "file" key. Fortunately, Mail::Sender's MailFile method allows you to specify an array of file names to attach:

    The file parameter may be a "filename", a "list, of, file, names" or a \@list_of_file_names.

    Try this:

    $sender->MailFile({to => $email_recipient, subject => $email_subject, file => [ $outfile, $file1 ], msg => $email_body});

      Thank you Aitap for your help, I have updated the code however I recieve the following error: syntax error at test_email.pl line 503, near "msg" this is the code i have used :
      send_email(); sub send_email { my $sender=new Mail::Sender({from =>$email_sender, fake_from =>$email_sender,smtp => 'mail.test.com'}); $sender->MailFile({to => $email_recipient, subject => $email_subject, file=> [ $outfile, $file1 ] msg => $email_body}); }
      edit - i added a comma after the file=> [ $outfile, $file1 ], and the syntax error is not showing anymore, however I'm not receiving any emails either ?!

        Sorry for the comma - I edited my message shortly after posting it and noticing the comma's absence.

        Try adding 'debug' parameter to the constructor to debug your messages.

        UPDATE- It works! just a bit slow in generating the email though:) Thank you!

Log In?
Username:
Password:

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

How do I use this? | Other CB clients
Other Users?
Others pondering the Monastery: (3)
As of 2016-09-25 16:09 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?
    Extraterrestrials haven't visited the Earth yet because:







    Results (470 votes). Check out past polls.