Beefy Boxes and Bandwidth Generously Provided by pair Networks
Clear questions and runnable code
get the best and fastest answer

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 = ''; print "Content-type: text/html\n\n"; my $sender = new Mail::Sender {smtp => '', from => ''}; $sender->MailFile({to => $email, subject => 'Welcome to you', msg => qq~ Welcome... ~, file => $host_serv, file => $prem_serv});

Replies are listed 'Best First'.
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?

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

How do I use this? | Other CB clients
Other Users?
Others having an uproarious good time at the Monastery: (7)
As of 2016-10-21 14:11 GMT
Find Nodes?
    Voting Booth?
    How many different varieties (color, size, etc) of socks do you have in your sock drawer?

    Results (289 votes). Check out past polls.