Beefy Boxes and Bandwidth Generously Provided by pair Networks
Perl: the Markov chain saw
 
PerlMonks  

Re: Re: Multi-Part email with Attachments using MIME::Lite

by filmo (Scribe)
on Aug 16, 2001 at 04:09 UTC ( [id://105240]=note: print w/replies, xml ) Need Help??


in reply to Re: Multi-Part email with Attachments using MIME::Lite
in thread Multi-Part email with Attachments using MIME::Lite

Perhaps I missread your reply, but it seems like the two examples simply create a single 'multipart/mixed' MIME. The first one sends some plain text and then attaches an HTML file. The second on sends some plain text and then attaches a word file (even though Type=> is set to octet-stream and not 'msword'.

What I'm looking to do is created a formatted e-mail body complete with all html code with a fall back to a simple plain text message if the receipient doesn't have a current email browser that can view HTML e-mails. In addition to those two parts, I also want to attach multiple attachements.

It seems that the correct way to do this is to set the header to 'multipart/mixed' and then define one of the multiparts as 'multipart/alternative' instead of 'text/plain' or 'text/html'. Within that sub-part, the 'text/plain' and 'text/html' are then created. Once the sub-part is "closed-out", then the attachments are added to the original 'multipart/mixed'
--
Filmo the Klown

  • Comment on Re: Re: Multi-Part email with Attachments using MIME::Lite

Replies are listed 'Best First'.
Re: Re: Re: Multi-Part email with Attachments using MIME::Lite
by tachyon (Chancellor) on Aug 16, 2001 at 06:33 UTC

    Now it becomes more clear what you want. I suggest you check out the MIME::Entity docs as you can mainpulate the parts to you hearts content.

    cheers

    tachyon

    s&&rsenoyhcatreve&&&s&n.+t&"$'$`$\"$\&"&ee&&y&srve&&d&&print

      Thanks for the help. After some playing around the MIME::Lite, I think I've figured it out. (at least it seems that way because the e-mails are working correctly now.) The trick was to build two MIMEs and attach the second one to the first

      Here's the modified code

      $email_msg = MIME::Lite->new ( Return-Path =>$from, From =>$from, To =>$email_to, Subject =>"Completed Transcripts ($count_trans +attached)", Type =>'multipart/mixed', Encoding =>'7bit' ); if ($cc_email) {$email_msg->add(CC =>$cc_email)} # Build Part 2 which is 'multipart/alternative' $body = MIME::Lite->new ( Type =>'multipart/alternative', Encoding =>'7bit', ); # Here's the fallback plain text message $body->attach( Type =>'text/plain', Encoding =>'7bit', Data =>$plain ); # Here's the HTML, nicely formated e-mail message + $body->attach( Type =>'text/html', Encoding =>'7bit', Data =>$html_body, ); # Attach the "body" part to the original message $email_msg->attach($body); # Attach "attachments" to original message foreach $file (sort keys %file_attach) { $email_msg->attach (Type =>'application/msword', Path =>$file_attach{$file}, Filename=>$file, Disposition=>'attachment', Encoding =>'base64' ); }
      This builds a "correctly" nested e-mail.
      --
      Filmo the Klown

        Hah - I came to the same conclusion and did this:

        use MIME::Entity; my $email = 'you@yours.com'; my $our_email = 'me@mine.com'; my $us = 'Just another Perl Hacker'; # create the alternative part with header my $alt = build MIME::Entity Type => 'multipart/alternative'; # now, make alternative attachment/s: attach $alt Path => "c:/text.txt", Type => 'text/HTML', Encoding => '7bit'; attach $alt Path => "c:/html.htm", Type => 'text/HTML', Encoding => '7bit'; # stringify our alternative part object $alt = $alt->as_string; # create the top-level, and set up the mail headers: my $top = build MIME::Entity Type => 'multipart/mixed', From => $our_email, To => $email, Subject => "Information from $us"; # next, add the alternate bodies of the message: attach $top Data => $alt; # now, make an attachment: attach $top Path => "c:/word.doc", Type => 'application/octet-stream', Encoding => 'base64'; # have a look at the result print $top->as_string;

        cheers

        tachyon

        s&&rsenoyhcatreve&&&s&n.+t&"$'$`$\"$\&"&ee&&y&srve&&d&&print

Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: note [id://105240]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others meditating upon the Monastery: (4)
As of 2024-04-25 05:15 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found