Skip Menu |

This queue is for tickets about the Net-SMTP-Multipart CPAN distribution.

Report information
The Basics
Id: 59031
Status: new
Priority: 0/
Queue: Net-SMTP-Multipart

People
Owner: Nobody in particular
Requestors: jdhedden [...] cpan.org
Cc:
AdminCc:

Bug Information
Severity: Important
Broken in: 1.6
Fixed in: (no value)



Subject: [PATCH] Cannot send to multiple recipients
The POD states that the 'To' parameter to '->Header()' can be an array of email addresses. However, neither: $smtp->Header(To => @emails, ... nor $smtp->Header(To => \@emails, ... works. The attached patch fixes this, and corrects to POD to specify using either a single email address or an array ref of addresses.
Subject: patch.txt
--- Net-SMTP-Multipart-1.6/Multipart.pm 2010-04-13 06:38:35.000000000 -0400 +++ Net-SMTP-Multipart-mod/Multipart.pm 2010-07-01 12:10:54.980427900 -0400 @@ -50,13 +50,14 @@ sub Header { my $self = shift; my %arg = @_; - carp 'Net::SMTP::Multipart:Header: must be called with a To value' unless $arg{To}; - carp 'Net::SMTP::Multipart:Header: must be called with a Subj value' unless $arg{Subj}; - carp 'Net::SMTP::Multipart:Header: must be called with a From value' unless $arg{From}; - $self->mail($arg{From}); # Sender Mail Address - $self->to($arg{To}); # Recpient Mail Address + carp 'Net::SMTP::Multipart:Header: must be called with a To value' unless $arg{To}; + carp 'Net::SMTP::Multipart:Header: must be called with a Subj value' unless $arg{Subj}; + carp 'Net::SMTP::Multipart:Header: must be called with a From value' unless $arg{From}; + $self->mail($arg{From}); # Sender Mail Address + my @recip = ref($arg{To}) ? @{$arg{To}} : $arg{To}; + $self->to(@recip); # Recipient Mail Address(es) $self->data(); - $self->datasend("To: $arg{To}\n"); + $self->datasend("To: ".join(", ", @recip)."\n"); $self->datasend("Subject: $arg{Subj}\n"); $self->datasend("MIME-Version: 1.0\n"); $self->datasend(sprintf "Content-Type: multipart/mixed; BOUNDARY=\"%s\"\n",$b); @@ -76,7 +77,7 @@ my $self = shift; my ($file, $filename); for $file (@_) { - unless (-f $file) { + unless (-f $file) { carp 'Net::SMTP::Multipart:FileAttach: unable to find file $file'; next; } @@ -103,13 +104,13 @@ # Keep only basename $filename = $file; $filename =~ s/^.*\/(.*?)/$1/; - + if ($data){ $self->datasend("--$b\n"); - $self->datasend("Content-Type: application/octet-stream; name=\"$filename\"\n"); + $self->datasend("Content-Type: application/octet-stream; name=\"$filename\"\n"); $self->datasend("Content-Transfer-Encoding: base64\n"); - $self->datasend("Content-Description: $filename\n"); - $self->datasend("Content-Disposition: attachment; filename=\"$filename\"\n\n"); + $self->datasend("Content-Description: $filename\n"); + $self->datasend("Content-Disposition: attachment; filename=\"$filename\"\n\n"); $self->datasend(encode_base64($data)); $self->datasend("--$b\n"); } @@ -160,9 +161,6 @@ $self->SUPER::quit(@_); } - - - 1; __END__ @@ -202,19 +200,26 @@ The B<Header> method creates the header of the multipart message. It should be called with the following arguments -=over 4 +=over 4 =item B<To> -an array of mail addresses to which the mail is to be sent +The mail address to which the mail is to be sent, or an array ref of +multiple recipients. + + $smtp->Header(To => "someone\@someco.com", + ... + or + $smtp->Header(To => [ "someone\@someco.com", "another\@email.addr" ], + ... =item B<From> -the mail address from which the mail is sent +The mail address from which the mail is sent =item B<Subj> -the subject title of the mail +The subject title of the mail =back