X-Git-Url: http://git.freeside.biz/gitweb/?a=blobdiff_plain;f=FS%2FFS%2FMisc.pm;h=71fe7e712f8df260709625d351e5afb2c1651cf3;hb=a638ae8bdba35169f61f2729d8f3491496992b55;hp=df971706852f0d0c88fc7f998a6fdf08d5125115;hpb=f7e1a877f69a8a144fc2da7a422c4e3f728321cb;p=freeside.git diff --git a/FS/FS/Misc.pm b/FS/FS/Misc.pm index df9717068..71fe7e712 100644 --- a/FS/FS/Misc.pm +++ b/FS/FS/Misc.pm @@ -41,12 +41,15 @@ I - (optional) MIME type I - (required) arrayref of body text lines +I - (optional) arrayref of MIME::Entity->build PARAMHASH refs, not MIME::Entity objects. These will be passed as arguments to MIME::Entity->attach(). + =cut use vars qw( $conf ); use Date::Format; use Mail::Header; use Mail::Internet 1.44; +use MIME::Entity; use FS::UID; FS::UID->install_callback( sub { @@ -58,23 +61,47 @@ sub send_email { $ENV{MAILADDRESS} = $options{'from'}; my $to = ref($options{to}) ? join(', ', @{ $options{to} } ) : $options{to}; - my @header = ( - 'From: '. $options{'from'}, - 'To: '. $to, - 'Sender: '. $options{'from'}, - 'Reply-To: '. $options{'from'}, - 'Date: '. time2str("%a, %d %b %Y %X %z", time), - 'Subject: '. $options{'subject'}, - ); - push @header, 'Content-Type: '. $options{'content-type'} - if exists($options{'content-type'}); - my $header = new Mail::Header ( \@header ); - my $message = new Mail::Internet ( - 'Header' => $header, - 'Body' => $options{'body'}, + my @mimeparts = (ref($options{'mimeparts'}) eq 'ARRAY') + ? @{$options{'mimeparts'}} : (); + my $mimetype = (scalar(@mimeparts)) ? 'multipart/mixed' : 'text/plain'; + + my @mimeargs; + if (scalar(@mimeparts)) { + @mimeargs = ( + 'Type' => 'multipart/mixed', + ); + + push @mimeparts, + { + 'Data' => $options{'body'}, + 'Disposition' => 'inline', + 'Type' => (($options{'content-type'} ne '') + ? $options{'content-type'} : 'text/plain'), + }; + } else { + @mimeargs = ( + 'Type' => (($options{'content-type'} ne '') + ? $options{'content-type'} : 'text/plain'), + 'Data' => $options{'body'}, + ); + } + + my $message = MIME::Entity->build( + 'From' => $options{'from'}, + 'To' => $to, + 'Sender' => $options{'from'}, + 'Reply-To' => $options{'from'}, + 'Date' => time2str("%a, %d %b %Y %X %z", time), + 'Subject' => $options{'subject'}, + @mimeargs, ); + foreach my $part (@mimeparts) { + next unless ref($part) eq 'HASH'; #warn? + $message->attach(%$part); + } + my $smtpmachine = $conf->config('smtpmachine'); $!=0; @@ -138,6 +165,9 @@ sub Mail::Internet::mysmtpsend { # Send it + #warn "Headers: \n" . join('',@{$hdr->header}); + #warn "Body: \n" . join('',@{$src->body}); + my $ok = $smtp->mail( $envelope ) && $smtp->to(@addr) && $smtp->data(join("", @{$hdr->header},"\n",@{$src->body}));