neilwatson has asked for the wisdom of the Perl Monks concerning the following question:

Using mail::sender I want to send an attachment but, the file contents is already residing in memory:

if ($nooatt > 0){ $sender->OpenMultipart({ smtp =>"$smtp", to =>"$callemail", from =>"$ticketad", fake_from =>"$ticketad", subject =>"Reply from Me: $callid", headers => "Errors-To: postmaster\@mydomain.com"}); die "Error: $Mail::Sender::Error\n" unless ref $sender; $sender->Body; $sender->SendLineEnc(<<"*END*"); $body *END* #build attachments for ($x=0; $x < $nooatt; $x++){ $sender->Attach({ description => "attachment$x", ctype => "$atttype[$x]", encoding => "Base64", disposition => "attachment; filename=\"$attname[$x]\"; type +=\"$atttype[$x]\"", file => "$attachment[$x]"}); die "Error: $Mail::Sender::Error\n" unless ref $sender; }

$attachment[$x] contains the contents of a file NOT the path to a file. Will this work? Is there another way to do it?

Neil Watson
watson-wilson.ca

Replies are listed 'Best First'.
Re: Sending email attachments with a twist
by fruiture (Curate) on Sep 18, 2002 at 19:38 UTC

    Ok, now i've installed this module and figured it out at last:

    Use the Part() Method just like the Body() Method and the use SendLineEnc (SendLine or print) to print to that Part of the message.

    my $snd = Mail::Sender->new({ smtp => ..., from => ..., }); $snd->OpenMultipart({ to => ..., from => ..., subject =>"TEST", }) or die "Error: $Mail::Sender::Error\n"; $snd->Body(0,0,'text/plain'); $snd->SendLineEnc('TEST EMAIL'); $snd->Attach({ description => "ATTCHMENT", ctype => "text/plain", disposition => "attachment; filename=\"xyz.txt\"; type +=\"text/plain\"", }) or die die "Error: $Mail::Sender::Error\n"; $snd->Part(); $snd->SendLineEnc('CONTENT OF ATTACHED FILE'); $snd->Close;

    Two more things: Please do not quote "$vars", there's something about it in perlfaq4 (`perldoc -q 'quote.*vars'`), and: I would never use a module that assumes text/html as default Content-Type for emails!

    --
    http://fruiture.de
Re: Sending email attachments with a twist
by neilwatson (Priest) on Sep 18, 2002 at 20:34 UTC
    Still not working for me :(. The code in the sent message looks like:

    --Message-Boundary-by-Mail-Sender-1032379780 Content-type: application/pdf Content-description: Platform_Pooling52_Release_Notes.pdf Content-transfer-encoding: 7BIT Content-disposition: attachment; filename="Platform_Pooling52_Release_ +Notes.pdf"; type="application/pdf" --Message-Boundary-by-Mail-Sender-1032379780 Content-type: application/octet-stream Content-transfer-encoding: 7BIT Content-disposition: attachment %PDF-1.2

    Neil Watson
    watson-wilson.ca