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> </p> <p>Please do the following quiz before you reply to this mail</p> <p> </p> <p>Regards</p> <p>CEO who ever</p>
In reply to Create email from html file with embedded images by Anonymous Monk
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |