Beefy Boxes and Bandwidth Generously Provided by pair Networks
laziness, impatience, and hubris
 
PerlMonks  

Attaching images on top/bottom of an already split mail entities

by chanakya (Friar)
on Aug 12, 2005 at 11:52 UTC ( [id://483252]=perlquestion: print w/replies, xml ) Need Help??

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

Greetings esteemed monks

I have an application which takes the incoming mail and spilts into entities using MIME::Parser and puts the mail entities in a randomly created directories for further spam checks. The structure will be like
j7BCVOSY008289 j7BCVOSY008289.header j7BD5BAI008933 j7BD5BAI008933. +header contents of j7BCVOSY008289 => msg-24072-2.html sample_image.gif contents of j7BD5BAI008933 => msg-24072-3.txt msg-24072-4.html
Now, for each mail entity which has an *.html file, I'd like to add an image one on top of the content (just after <body> tag) and one image at the bottom (just before </body> tag), similar to the code below
$msg = MIME::Lite->new( To =>'you@yourhost.com', Subject =>'HTML with in-line images!', Type =>'multipart/related' ); $msg->attach(Type => 'text/html', Data => qq{ <body> Here's <i>my</i> image: <img src="cid:head_image.jpg"> Some content here..blah blah blah <img src="cid:bottom_image.jpg"> </body> } ); $msg->attach(Type => 'image/jpg', Id => 'head_image.jpg', Path => '/path/to/head_image.jpg', ); $msg->attach(Type => 'image/jpg', Id => 'bottom_image.jpg', Path => '/path/to/bottom_image.jpg', );
I'm a little confused going about adding new entities to already splitted entities.
Can someone give me an idea about going about the same. How this can be achieved using MIME::Tools

Thank you in advance for your time
May the force be with you !!

Replies are listed 'Best First'.
Re: Attaching images on top/bottom of an already split mail entities
by zentara (Archbishop) on Aug 12, 2005 at 12:22 UTC
    Hi, the code below works for me, and I see 2 major differences. You may need the Type and Encoding for the image attachments, and/or try 'multipart/related'.
    my $mime_type = 'multipart/related'; # Create the message headers my $mime_msg = MIME::Lite->new( From => $from_address, To => $to_address, Subject => $subject, Type => $mime_type ) or die "Error creating MIME body: $!\n"; # Attach the HTML content my $message_body = '<html><body><H3>Hello world! <img src="cid:myid.gif"></H3></body></html>'; $mime_msg->attach(Type => 'text/html', Data => $message_body); # Attach the image $mime_msg->attach( Type => 'image/gif', Id => 'myid.gif', Encoding => 'base64', Path => 'pikachu.jpg'); $mime_msg->send;

    I'm not really a human, but I play one on earth. flash japh

Log In?
Username:
Password:

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

How do I use this?Last hourOther CB clients
Other Users?
Others lurking in the Monastery: (2)
As of 2024-04-26 00:27 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found