Solved

MIME::Lite::TT::HTMLProblem -  Unable to see HTML images on the mail client

Posted on 2008-10-20
8
1,326 Views
Last Modified: 2013-12-25
Hi There,

I am using MIME::Lite::TT::HTML Perl module to send an HTML based email. HTML file contains a header image and footer image and the content within. When I send an email using this module, I can see on the mail client only the text content and not the header and footer images.

- I am sure the images are in the same path as the html files is and as well I tried giving absolute path of images in the HTML file as well. But nothing works.

Can some one guide me on what I need to do so that I can see header and footer images when I see the mail in my mail client ?

Thanks
test.pl
----------
 
use strict; 
use warnings; 
use MIME::Lite::TT::HTML; 
 
my %params; 
 
$params{first_name} = 'foo'; 
$params{last_name}  = 'bar'; 
$params{date}    = 'Oct 20, 2008';
 
my %options; 
$options{INCLUDE_PATH} = '/path/to/templates'; 
 
my $msg = MIME::Lite::TT::HTML->new( 
            From        =>  'x@abc.com',
            To          =>  'y@abc.com', 
            Cc          =>  'z@abc.com', 
            Subject     =>  'Your recent purchase', 
            Template    =>  {
                                #text    =>  'text.txt',
                                html    =>  'test.html',
                            },
            TmplOptions =>  \%options, 
            TmplParams  =>  \%params, 
); 
 
$msg->attr("content-type" => "multipart/mixed");
 
 # send the email
MIME::Lite->send('smtp', 'smtp.ss.xyz.com', Timeout => 60);
$msg->send; 
print "Ok!\n";
------------------------------------------------------------------------
 
test.html
----------
 
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=ISO-8859-1" />
<title>SPOT Satellite Messenger</title>
<style type="text/css">
<!--
body,td,th {
	font-family:Arial, Helvetica, sans-serif;
	font-size: 12px;
	color: #333333;
}
body {
	margin-left: 0px;
	margin-top: 0px;
}
a {
	color: #333333;
	text-decoration: none;
}
-->
</style>
</head>
 
<body>
<p><img src="/images/header.jpg" width="719" height="91" /></p>
<blockquote>
  <p>Dear [% first_name %],</p>
  <p>Thank you for your continued service with X<br />
    [% date %]
    .</p>
  <p>Thank you,</p>
  <p>Customer Care<br />
  </p>
  <p>&nbsp;</p>
  <p>&nbsp;</p>
  <p> </p>
  <p>&nbsp;</p>
  <p>&nbsp;</p>
</blockquote>
<p><img src="/images/footer.jpg" width="720" height="44" border="0" usemap="#Map" />
<map name="Map" id="Map"><area shape="rect" coords="572,14,708,34" href="http://www.xyz.com" />
</map></p>
</body>
</html>

Open in new window

0
Comment
Question by:hSindhu
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 5
  • 3
8 Comments
 
LVL 10

Expert Comment

by:Tobias
ID: 22765222
Hi !

Is one solution :

Tell my it's satisfy to you.

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=ISO-8859-1" />
<title>SPOT Satellite Messenger</title>
<style type="text/css">
<!--
body,td,th {
        font-family:Arial, Helvetica, sans-serif;
        font-size: 12px;
        color: #333333;
}
body {
        margin-left: 0px;
        margin-top: 0px;
}
a {
        color: #333333;
        text-decoration: none;
}
-->
</style>
</head>
 
<body>
<p><img src="http://www.yoursite.com/images/header.jpg" width="719" height="91" /></p>
<blockquote>
  <p>Dear [% first_name %],</p>
  <p>Thank you for your continued service with X<br />
    [% date %]
    .</p>
  <p>Thank you,</p>
  <p>Customer Care<br />
  </p>
  <p> </p>
  <p> </p>
  <p> </p>
  <p> </p>
  <p> </p>
</blockquote>
<p><img src="http://www.yoursite.com/images/footer.jpg" width="720" height="44" border="0" usemap="#Map" />
<map name="Map" id="Map"><area shape="rect" coords="572,14,708,34" href="http://www.xyz.com" />
</map></p>
</body>
</html>
0
 

Author Comment

by:hSindhu
ID: 22769132
Hi Shiva,

I was looking for how we can get the images on the email client using use MIME::Lite::TT::HTML; . Is it that you missed the PERL Code? I am only seeing the HTML template. Please let me know. If possible can you paste the full code snippet.

Thanks
0
 

Author Comment

by:hSindhu
ID: 22769134
Hi Shiva,

I was looking for how we can get the images on the email client using use MIME::Lite::TT::HTML; . Is it that you missed the PERL Code? I am only seeing the HTML template. Please let me know. If possible can you paste the full code snippet.

Thanks
0
Business Impact of IT Communications

What are the business impacts of how well businesses communicate during an IT incident? Targeting, speed, and transparency all matter. Find out more in this infographic.

 
LVL 10

Expert Comment

by:Tobias
ID: 22773924
Hi hSindhu !

Yes I don't have put the Perl code because I don't have change them. You have two solution. First I think is to attach the image in the mail or choose one full link like http://something.com.

I have give you the second solution.


Now is the first :


test.pl
----------
 
use strict;
use warnings;
use MIME::Lite::TT::HTML;
 
my %params;
 
$params{first_name} = 'foo';
$params{last_name}  = 'bar';
$params{date}    = 'Oct 20, 2008';
 
my %options;
$options{INCLUDE_PATH} = '/path/to/templates';
 
my $msg = MIME::Lite::TT::HTML->new(
            From        =>  'x@abc.com',
            To          =>  'y@abc.com',
            Cc          =>  'z@abc.com',
            Subject     =>  'Your recent purchase',
            Template    =>  {
                                #text    =>  'text.txt',
                                html    =>  'test.html',
                            },
            TmplOptions =>  \%options,
            TmplParams  =>  \%params,
);
 
$msg->attr("content-type" => "multipart/mixed");


my $header_path = '/images/header.jpg';

my $footer_path = '/images/footer.jpg';


$msg->attach(  Type        =>  'image/jpeg',
                Path        =>  $header_path,
                Filename    =>  'header.jpg',
                Disposition =>  'attachment'
 );

$msg->attach(  Type        =>  'image/jpeg',
                Path        =>  $footer_path,
                Filename    =>  'footer.jpg',
                Disposition =>  'attachment'
 );

 
 # send the email
MIME::Lite->send('smtp', 'smtp.ss.xyz.com', Timeout => 60);
$msg->send;
print "Ok!\n";


Sorry but i can't try it now. I hope this work.

Best Regards
0
 

Author Comment

by:hSindhu
ID: 22773946
Hi Shiva,

Let me try this snippet and I will keep you posted if that worked.

Thanks!
0
 

Author Comment

by:hSindhu
ID: 22781891
Hi Shiva,

I dont wish to give a http path for my image files. I want to give an absolute path like Ex: "/home/sin/test" in the code. I tried to test your code and I dont see the images in the email. I just got the images as an attachment in the email. Can you please paste a working code snippet so that I can test it?

Thanks!
0
 
LVL 10

Accepted Solution

by:
Tobias earned 50 total points
ID: 22783610
Hi !

Yes it's what I am not sur.

$msg->attach(  Type        =>  'image/jpeg',
                Path        =>  $footer_path,
                Filename    =>  'footer.jpg',
                Disposition =>  'attachment'
 );


try with remove the part : Disposition =>  'attachment'


Also I have find this snippet that you can adjust and try.

If it's not working I can try at home.


Best Regards


use strict;
use warnings;
use 5.010;
 
use MIME::Lite;
use HTML::TreeBuilder; # or what you like most
use File::Basename;
use File::Type;
 
# ...
 
sub makemsg {
    my (%id, %saw);
    (my $tree=HTML::TreeBuilder->new)->parse_file(shift);
    for my $img ($tree->look_down(_tag => 'img')) {
        defined(my $imgname=$img->attr('src')) or 
          warn "[$0] Warning: img tag with no src attribute!" and next
+;
        unless($id{$imgname}) {
            # not necessary, but I prefer it like that!
            (my $id=basename $imgname) =~ s/_*[^\w]+/_/g;
            $id++ while exists $saw{$id};
            $saw{$id}++;
            $id{$imgname}=$id;
        }
        $img->attr(src => "cid:$id{$imgname}");
    }
    my $msg=MIME::Lite->new(
        To =>'someone@example.org',
        Subject =>'HTML with in-line images!',
        Type =>'multipart/related');
    $msg->attach(
        Type => 'text/html',
        Data => $tree->as_HTML);
    
    $tree->delete; # However ugly, it's necessary!
    
    my $ft=File::Type->new;
    for (keys %id) {
        $msg->attach(
            Type => $ft->checktype_filename($_) // 'image/xyz',
            Id   => $id{$_},
            Path => $_);
    }
    $msg;
}

Open in new window

0
 

Author Closing Comment

by:hSindhu
ID: 31508087
Thanks for your help!
0

Featured Post

Is Your Team Achieving Their Full Potential?

74% of employees feel they are not achieving their full potential. With Linux Academy, not only will you strengthen your team's core competencies but also their knowledge of of the newest IT topics.

With new material every week, we'll make sure that you stay ahead of the game.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

The Windows functions GetTickCount and timeGetTime retrieve the number of milliseconds since the system was started. However, the value is stored in a DWORD, which means that it wraps around to zero every 49.7 days. This article shows how to solve t…
Although a lot of people devote their energy toward marketing for specific industries, there are some basic principles that can be applied to any sector imaginable. We’ll look at four steps to take and examine how those steps were put into action fo…
Learn how to create flexible layouts using relative units in CSS.  New relative units added in CSS3 include vw(viewports width), vh(viewports height), vmin(minimum of viewports height and width), and vmax (maximum of viewports height and width).
In a recent question (https://www.experts-exchange.com/questions/29004105/Run-AutoHotkey-script-directly-from-Notepad.html) here at Experts Exchange, a member asked how to run an AutoHotkey script (.AHK) directly from Notepad++ (aka NPP). This video…

705 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question