Hi Fellow monks
Thank you for your help

I've been learning from the site for the past two days on how to send emails with attachments and received wonderfull insight, so if you recognise some of you code thank you

I am able to send a mail with MIME::Lite. I can attach files, and I've received a nice piece of code that searches through the html file for any pictures and attaches it aswell

My problem is that I need to create a email from a template html file, the file might contain pictures and need to embed the picture in the template into the email. I know you use something like this src="cid:000f92fd680$7900a8c0@whatever" but have no Idea how to create the cid number to refer to the image inside the mail (I hope you pick up where my cofusion lies. Below is my code and the html template in html

#!c:\perl\bin # Compiler directives and Includes use Mime::Lite; use HTML::LinkExtor; unless (open(LOG, ">log.txt")) { die ("cannot open log.txt file \n"); } unless (open(TEMPLATE, "htmlfile.htm")) { die ("cannot open paris.htm file \n"); } $from = 'herman'; $to = 'tomail@whoever.co.za'; $cc = ''; $path = "att"; $att = "exclam.gif"; $bodytype = "multipart/mixed"; #if mail has attachments use multipart $subject = "Hello template"; $body=''; while(<TEMPLATE>) { $body .= $record; } #while(<TEMPLATE>) $mtype = "gif"; open (STDERR, ">&LOG"); my %mimeTypes = (); $mimeTypes{'gif'} = "image/gif"; ## Create the multipart "container": $msg = MIME::Lite->new( From =>$from, To =>$to, Cc =>$cc, Subject =>$subject, Type =>$bodytype ); ### Add the text message part: ### (Note that "attach" has same arguments as "new"): $msg->attach(Type =>'text/html', Data =>$body ); ### Attach Images that are embedded in the html body to the mail ### This is where I'll need to get these linked images as embedded ima +ges my $parser = HTML::LinkExtor->new(); $parser->parse($body); foreach my $link ($parser->links){ if ($link->[0] eq 'img'){ print LOG ("Image found [".$link->[2]."] "); if ($link->[2] =~ /^https?:\/\//){ print LOG ("Absolute! Ignored.\n"); }else{ my ($imgtype,$junk) = reverse split '\.',$link->[2]; $imgtype =~ s/^jpg$/jpeg/; #propper mime name? if(open(TEST,"<".$link->[2])){ print LOG ("Attaching\n"); close(TEST); $msg->attach(Type =>'image/'.$imgtype, Path =>$link->[2], Filename=>$link->[2], Disposition => 'inline'); #Disposition => 'attachment'); }else{ print LOG ("Not found, Skipped!!\n"); } } } } ### Attach all the the files required to be attached $tmp = (exists($mimeTypes{$mtype})) ? $mimeTypes{$mtype} : 'application/octet-stream' ; ### Add the file part: $msg->attach(Type =>$tmp, Path =>"$path\\$att", Filename =>$att, Disposition => 'attachment' ); ### Send Mail MIME::Lite->send('smtp', "whoever", Timeout=>60); $test = $msg->send; # send email print "$test\n\n\n\n";
<p><img src="att/image002.gif" width="136" height="137"></p> <p>Dear mr #entity_name#</p> <p>&nbsp;</p> <p>Please do the following quiz before you reply to this mail</p> <p>&nbsp;</p> <p>Regards</p> <p>CEO who ever</p>

In reply to Create email from html file with embedded images by Anonymous Monk

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.