Beefy Boxes and Bandwidth Generously Provided by pair Networks
We don't bite newbies here... much
 
PerlMonks  

mail::sender question

by jonnyfolk (Vicar)
on Feb 24, 2008 at 18:53 UTC ( #669858=perlquestion: print w/ replies, xml ) Need Help??
jonnyfolk has asked for the wisdom of the Perl Monks concerning the following question:

How do I get the email to send out two attachments - currently it's sending two emails?
#!/usr/bin/perl -w use strict; use CGI::Carp qw(fatalsToBrowser warningsToBrowser); use CGI ':standard'; use Mail::Sender; my $host_serv = '/path/host_serv.pdf'; my $prem_serv = '/path/prem_serv.pdf'; my $email = 'jon@moi.com'; print "Content-type: text/html\n\n"; my $sender = new Mail::Sender {smtp => 'mail.mysite.com', from => 'me@site.com'}; $sender->MailFile({to => $email, subject => 'Welcome to you', msg => qq~ Welcome... ~, file => $host_serv, file => $prem_serv});

Comment on mail::sender question
Download Code
Re: mail::sender question
by almut (Canon) on Feb 24, 2008 at 19:26 UTC
    file => $host_serv, file => $prem_serv});

    Try file => [$host_serv, $prem_serv] or file => "$host_serv, $prem_serv" instead.

    (Untested — but that's how I'd interpret the docs.)

Re: mail::sender question
by hesco (Deacon) on Feb 25, 2008 at 07:26 UTC
    I use MIME::Lite for this sort of task.

    Here is some code from a module I have which sends emails to a list pulled from a database:

    if(defined($email->{'attachments'}->{'count'})){ $msg = MIME::Lite->new( From => "$email->{'from'}", To => "$row->{$email->{'db'}->{'email_field'}}", Subject => "$subject", Type => 'multipart/mixed', ); if(defined($email->{'cvr_ltr_html'})){ # attach html cover letter $msg->attach( Type => 'text/html', Data => $copy_html, ); } else { # attach plain text cover letter $msg->attach( Type => 'TEXT', Data => "$copy", ); } } else { # print "We now produce a plain text email message.\n"; $msg = MIME::Lite->new( From => "$email->{'from'}", To => "$row->{$email->{'db'}->{'email_field'}}", Subject => "$subject", Data => $copy, ); } if(defined($email->{'attachments'}->{'count'})){ for my $i (1 .. $email->{'attachments'}->{'count'}){ # print STDERR $email->{'attachments'}->{$i}->{'Content-type'}," +\n"; # print STDERR $email->{'attachments'}->{$i}->{'file-path'},"\n" +; $msg->attach( Type => $email->{'attachments'}->{$i}->{'Content-t +ype'}, Disposition => $email->{'attachments'}->{$i}->{'dispositi +on'}, Path => $email->{'attachments'}->{$i}->{'file-path +'}, Filename => $email->{'attachments'}->{$i}->{'filename' +}, Encoding => 'base64', ); } } my $smtp = Net::SMTP->new($mailhost, Hello => $email->{'hello'}, Debug => 0 ) or return 0; my $data = $msg->body_as_string; my $header = $msg->header_as_string; $smtp->to($row->{$email->{'db'}->{'email_field'}}); $smtp->data(); $smtp->datasend("$header"); $smtp->datasend("\n\n"); $smtp->datasend("$data \n"); $smtp->dataend(); $smtp->quit;
    if( $lal && $lol ) { $life++; }

Log In?
Username:
Password:

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

How do I use this? | Other CB clients
Other Users?
Others drinking their drinks and smoking their pipes about the Monastery: (9)
As of 2014-11-21 02:56 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    My preferred Perl binaries come from:














    Results (104 votes), past polls