Prev: Problems with function dump_entity from example distributed with MIME::tools
Next: MIME::Lite and AUTH only after STARTTLS (smtp.gmail.com)
From: Peter J. Holzer on 19 Jun 2010 10:02 On 2010-06-19 02:00, Ted Byers <r.ted.byers(a)gmail.com> wrote: > I wonder if I need to uuencode it, No. Uuencode is sort of a precursor to MIME. You should use either MIME or uuencode, but not both. In fact, since MIME can do everything uuencode can (and much more) and is actually standardized, you should always use MIME and never use uuencode (unless you need to talk to some legacy software from the 1980's). hp
From: Ted Byers on 21 Jun 2010 11:42 On Jun 19, 9:56 am, "Peter J. Holzer" <hjp-usen...(a)hjp.at> wrote: > On 2010-06-18 22:22, Ted Byers <r.ted.by...(a)gmail.com> wrote: > > > > > While the html displays OK, the top haif of it is repeated at the end. > > Equally badly, the link between the jpg file (containing the logo) and > > the img tag in the html is broken. > > > The first few lines, showing the package I am using are: > [...] > > use Email::MIME::Creator; > [...] > > my $html_part = Email::MIME->create( > > attributes => { > > content_type => "text/html", > > }, > > body => "$html_template", > > ); > > my $image_part = Email::MIME->create( > > attributes => { > > content_type => "image/jpg", > > name => "logo.jpg", > > }, > > body => io( "template.files/image002.jpg" )->all, > > ); > > my @parts = ($html_part,$image_part); > > my $message = Email::MIME->create( > > header => [ > > From => 'con...(a)capitalbusinessservices.net', > > To => 'r.ted.by...(a)gmail.com', > > Subject => $subject, > > ], > > parts => \@parts, > > ); > [...] > > It could hardly be simpler. > > > The img tag is: > > ><img width=634 height=95 src="logo.jpg" v:shapes="_x0000_i1025"> > > That doesn't work. You cannot use a relative URL like "logo.jpg" in an > email. You can either use an http: URL (but many mailers won't resolve > them by default for privacy reasons (google "web bugs" for details)) or > a cid: URL to refer to an image within the email (this is a better idea > and obviously what you are trying to do). To use cid: URLs, all the > related parts of the message (in this case the HTML part and the image) > need to be enclosed in a multipart/related message. You don't seem to do > that. > > Here is an example using MIME::Lite to build an HTML mail with embedded > images. Adapting it to Email::MIME::Creator is left as an exercise to > the reader: > > #!/usr/bin/perl > use warnings; > use strict; > > use MIME::Lite; > > my $msg = MIME::Lite->new( > From => 'hjp-usen...(a)hjp.at', > To => 'hjp-usen...(a)hjp.at', > Subject => 'HTML test message', > Type => 'multipart/related; type=text/html', > ); > > my $unique = time(); > my $tb_logo_cid = "tb-logo.$unique\@hjp.at"; > my $smiley_cid = "smiley.$unique\@hjp.at"; > > $msg->attach( > Type => 'text/html; charset=UTF-8', > Data => "<title>Message text</title>\n" . > "<h1>Hallo</h1>\n" . > "<p>Hier ist ein Text mit einem Bild:</p>\n" . > "<p><img alt='TB Logo' src='cid:$tb_logo_cid'></p>\n" . > "<p>Es funktioniert! <img alt=':-)' src='cid:$smiley_cid'></p>\n", > ); > > my $part = MIME::Lite->new( > Type => 'image/png', > Path => 'Mozilla_Thunderbird_logo.png', > ); > $part->attr('Content-Id', "<$tb_logo_cid>"); > $msg->attach($part); > > $part = MIME::Lite->new( > Type => 'image/gif', > Path => 'smiley16.gif', > ); > $part->attr('Content-Id', "<$smiley_cid>"); > $msg->attach($part); > > $msg->print(\*STDOUT); > __END__ > > hp Thanks All, I have tried everything suggested in this thread. Always the result was the same, even after using cid as directed. I do not understand why. However, I do have progress. In my quest for additional information, I found Email::MIME::CreateHTML. It does make things much simpler. With it, I need only two statements to make the message: my %objects = ( "logo.jpg" => "template.files/image002.jpg" ); $message = Email::MIME->create_html( header => [ From => $from_user, To => $to_user, Subject => "testing Connie's email", ], body => $html_template, embed => 0, #<-- inline_css => 0, #<-- objects => \%objects #<-- ); The improvement this produces is twofold. First, the html body is invariably properly displayed. Second, ythe linked in image is displayed in the right place. However, also invariably, only half of the logo.jpg is displayed; this despite there being enough space being available in the browser to display it all. The body of the html file now begins with: <p><img width="634" height="95" src='cid:logo.jpg'></p> NB: The result is the same regardless of whether I use a file named logo.jpg or template.files/image002.jpg. If I use the following: my $logo = io( "logo.jpg" )->binary->all; open(FOUT,"> logo.output.jpg"); binmode(FOUT); print FOUT $logo; close(FOUT); I can compare the images using both Windows explorer and Irfanview, and the files (logo.jpg and logo.output.jpg) are identical. However, when I download and examine the image that accompanies the email, I see it is defective. Any ideas on why the image sent with the email is defective and how that can be fixed? Thanks Ted
From: Ted Byers on 21 Jun 2010 11:43 On Jun 19, 9:56 am, "Peter J. Holzer" <hjp-usen...(a)hjp.at> wrote: > On 2010-06-18 22:22, Ted Byers <r.ted.by...(a)gmail.com> wrote: > > > > > While the html displays OK, the top haif of it is repeated at the end. > > Equally badly, the link between the jpg file (containing the logo) and > > the img tag in the html is broken. > > > The first few lines, showing the package I am using are: > [...] > > use Email::MIME::Creator; > [...] > > my $html_part = Email::MIME->create( > > attributes => { > > content_type => "text/html", > > }, > > body => "$html_template", > > ); > > my $image_part = Email::MIME->create( > > attributes => { > > content_type => "image/jpg", > > name => "logo.jpg", > > }, > > body => io( "template.files/image002.jpg" )->all, > > ); > > my @parts = ($html_part,$image_part); > > my $message = Email::MIME->create( > > header => [ > > From => 'con...(a)capitalbusinessservices.net', > > To => 'r.ted.by...(a)gmail.com', > > Subject => $subject, > > ], > > parts => \@parts, > > ); > [...] > > It could hardly be simpler. > > > The img tag is: > > ><img width=634 height=95 src="logo.jpg" v:shapes="_x0000_i1025"> > > That doesn't work. You cannot use a relative URL like "logo.jpg" in an > email. You can either use an http: URL (but many mailers won't resolve > them by default for privacy reasons (google "web bugs" for details)) or > a cid: URL to refer to an image within the email (this is a better idea > and obviously what you are trying to do). To use cid: URLs, all the > related parts of the message (in this case the HTML part and the image) > need to be enclosed in a multipart/related message. You don't seem to do > that. > > Here is an example using MIME::Lite to build an HTML mail with embedded > images. Adapting it to Email::MIME::Creator is left as an exercise to > the reader: > > #!/usr/bin/perl > use warnings; > use strict; > > use MIME::Lite; > > my $msg = MIME::Lite->new( > From => 'hjp-usen...(a)hjp.at', > To => 'hjp-usen...(a)hjp.at', > Subject => 'HTML test message', > Type => 'multipart/related; type=text/html', > ); > > my $unique = time(); > my $tb_logo_cid = "tb-logo.$unique\@hjp.at"; > my $smiley_cid = "smiley.$unique\@hjp.at"; > > $msg->attach( > Type => 'text/html; charset=UTF-8', > Data => "<title>Message text</title>\n" . > "<h1>Hallo</h1>\n" . > "<p>Hier ist ein Text mit einem Bild:</p>\n" . > "<p><img alt='TB Logo' src='cid:$tb_logo_cid'></p>\n" . > "<p>Es funktioniert! <img alt=':-)' src='cid:$smiley_cid'></p>\n", > ); > > my $part = MIME::Lite->new( > Type => 'image/png', > Path => 'Mozilla_Thunderbird_logo.png', > ); > $part->attr('Content-Id', "<$tb_logo_cid>"); > $msg->attach($part); > > $part = MIME::Lite->new( > Type => 'image/gif', > Path => 'smiley16.gif', > ); > $part->attr('Content-Id', "<$smiley_cid>"); > $msg->attach($part); > > $msg->print(\*STDOUT); > __END__ > > hp Thanks All, I have tried everything suggested in this thread. Always the result was the same, even after using cid as directed. I do not understand why. However, I do have progress. In my quest for additional information, I found Email::MIME::CreateHTML. It does make things much simpler. With it, I need only two statements to make the message: my %objects = ( "logo.jpg" => "template.files/image002.jpg" ); $message = Email::MIME->create_html( header => [ From => $from_user, To => $to_user, Subject => "testing Connie's email", ], body => $html_template, embed => 0, #<-- inline_css => 0, #<-- objects => \%objects #<-- ); The improvement this produces is twofold. First, the html body is invariably properly displayed. Second, ythe linked in image is displayed in the right place. However, also invariably, only half of the logo.jpg is displayed; this despite there being enough space being available in the browser to display it all. The body of the html file now begins with: <p><img width="634" height="95" src='cid:logo.jpg'></p> NB: The result is the same regardless of whether I use a file named logo.jpg or template.files/image002.jpg. If I use the following: my $logo = io( "logo.jpg" )->binary->all; open(FOUT,"> logo.output.jpg"); binmode(FOUT); print FOUT $logo; close(FOUT); I can compare the images using both Windows explorer and Irfanview, and the files (logo.jpg and logo.output.jpg) are identical. However, when I download and examine the image that accompanies the email, I see it is defective. Any ideas on why the image sent with the email is defective and how that can be fixed? Thanks Ted
From: Ted Byers on 21 Jun 2010 12:02 On Jun 19, 9:56 am, "Peter J. Holzer" <hjp-usen...(a)hjp.at> wrote: > On 2010-06-18 22:22, Ted Byers <r.ted.by...(a)gmail.com> wrote: > > > > > While the html displays OK, the top haif of it is repeated at the end. > > Equally badly, the link between the jpg file (containing the logo) and > > the img tag in the html is broken. > > > The first few lines, showing the package I am using are: > [...] > > use Email::MIME::Creator; > [...] > > my $html_part = Email::MIME->create( > > attributes => { > > content_type => "text/html", > > }, > > body => "$html_template", > > ); > > my $image_part = Email::MIME->create( > > attributes => { > > content_type => "image/jpg", > > name => "logo.jpg", > > }, > > body => io( "template.files/image002.jpg" )->all, > > ); > > my @parts = ($html_part,$image_part); > > my $message = Email::MIME->create( > > header => [ > > From => 'con...(a)capitalbusinessservices.net', > > To => 'r.ted.by...(a)gmail.com', > > Subject => $subject, > > ], > > parts => \@parts, > > ); > [...] > > It could hardly be simpler. > > > The img tag is: > > ><img width=634 height=95 src="logo.jpg" v:shapes="_x0000_i1025"> > > That doesn't work. You cannot use a relative URL like "logo.jpg" in an > email. You can either use an http: URL (but many mailers won't resolve > them by default for privacy reasons (google "web bugs" for details)) or > a cid: URL to refer to an image within the email (this is a better idea > and obviously what you are trying to do). To use cid: URLs, all the > related parts of the message (in this case the HTML part and the image) > need to be enclosed in a multipart/related message. You don't seem to do > that. > > Here is an example using MIME::Lite to build an HTML mail with embedded > images. Adapting it to Email::MIME::Creator is left as an exercise to > the reader: > > #!/usr/bin/perl > use warnings; > use strict; > > use MIME::Lite; > > my $msg = MIME::Lite->new( > From => 'hjp-usen...(a)hjp.at', > To => 'hjp-usen...(a)hjp.at', > Subject => 'HTML test message', > Type => 'multipart/related; type=text/html', > ); > > my $unique = time(); > my $tb_logo_cid = "tb-logo.$unique\@hjp.at"; > my $smiley_cid = "smiley.$unique\@hjp.at"; > > $msg->attach( > Type => 'text/html; charset=UTF-8', > Data => "<title>Message text</title>\n" . > "<h1>Hallo</h1>\n" . > "<p>Hier ist ein Text mit einem Bild:</p>\n" . > "<p><img alt='TB Logo' src='cid:$tb_logo_cid'></p>\n" . > "<p>Es funktioniert! <img alt=':-)' src='cid:$smiley_cid'></p>\n", > ); > > my $part = MIME::Lite->new( > Type => 'image/png', > Path => 'Mozilla_Thunderbird_logo.png', > ); > $part->attr('Content-Id', "<$tb_logo_cid>"); > $msg->attach($part); > > $part = MIME::Lite->new( > Type => 'image/gif', > Path => 'smiley16.gif', > ); > $part->attr('Content-Id', "<$smiley_cid>"); > $msg->attach($part); > > $msg->print(\*STDOUT); > __END__ > > hp Thanks All, I have tried everything suggested in this thread. Always the result was the same, even after using cid as directed. I do not understand why. However, I do have progress. In my quest for additional information, I found Email::MIME::CreateHTML. It does make things much simpler. With it, I need only two statements to make the message: my %objects = ( "logo.jpg" => "template.files/image002.jpg" ); $message = Email::MIME->create_html( header => [ From => $from_user, To => $to_user, Subject => "testing Connie's email", ], body => $html_template, embed => 0, #<-- inline_css => 0, #<-- objects => \%objects #<-- ); The improvement this produces is twofold. First, the html body is invariably properly displayed. Second, ythe linked in image is displayed in the right place. However, also invariably, only half of the logo.jpg is displayed; this despite there being enough space being available in the browser to display it all. The body of the html file now begins with: <p><img width="634" height="95" src='cid:logo.jpg'></p> NB: The result is the same regardless of whether I use a file named logo.jpg or template.files/image002.jpg. If I use the following: my $logo = io( "logo.jpg" )->binary->all; open(FOUT,"> logo.output.jpg"); binmode(FOUT); print FOUT $logo; close(FOUT); I can compare the images using both Windows explorer and Irfanview, and the files (logo.jpg and logo.output.jpg) are identical. However, when I download and examine the image that accompanies the email, I see it is defective. Any ideas on why the image sent with the email is defective and how that can be fixed? Thanks Ted
From: Ted Byers on 21 Jun 2010 16:14
On Jun 19, 9:56 am, "Peter J. Holzer" <hjp-usen...(a)hjp.at> wrote: > On 2010-06-18 22:22, Ted Byers <r.ted.by...(a)gmail.com> wrote: > > > > > While the html displays OK, the top haif of it is repeated at the end. > > Equally badly, the link between the jpg file (containing the logo) and > > the img tag in the html is broken. > > > The first few lines, showing the package I am using are: > [...] > > use Email::MIME::Creator; > [...] > > my $html_part = Email::MIME->create( > > attributes => { > > content_type => "text/html", > > }, > > body => "$html_template", > > ); > > my $image_part = Email::MIME->create( > > attributes => { > > content_type => "image/jpg", > > name => "logo.jpg", > > }, > > body => io( "template.files/image002.jpg" )->all, > > ); > > my @parts = ($html_part,$image_part); > > my $message = Email::MIME->create( > > header => [ > > From => 'con...(a)capitalbusinessservices.net', > > To => 'r.ted.by...(a)gmail.com', > > Subject => $subject, > > ], > > parts => \@parts, > > ); > [...] > > It could hardly be simpler. > > > The img tag is: > > ><img width=634 height=95 src="logo.jpg" v:shapes="_x0000_i1025"> > > That doesn't work. You cannot use a relative URL like "logo.jpg" in an > email. You can either use an http: URL (but many mailers won't resolve > them by default for privacy reasons (google "web bugs" for details)) or > a cid: URL to refer to an image within the email (this is a better idea > and obviously what you are trying to do). To use cid: URLs, all the > related parts of the message (in this case the HTML part and the image) > need to be enclosed in a multipart/related message. You don't seem to do > that. > > Here is an example using MIME::Lite to build an HTML mail with embedded > images. Adapting it to Email::MIME::Creator is left as an exercise to > the reader: > > #!/usr/bin/perl > use warnings; > use strict; > > use MIME::Lite; > > my $msg = MIME::Lite->new( > From => 'hjp-usen...(a)hjp.at', > To => 'hjp-usen...(a)hjp.at', > Subject => 'HTML test message', > Type => 'multipart/related; type=text/html', > ); > > my $unique = time(); > my $tb_logo_cid = "tb-logo.$unique\@hjp.at"; > my $smiley_cid = "smiley.$unique\@hjp.at"; > > $msg->attach( > Type => 'text/html; charset=UTF-8', > Data => "<title>Message text</title>\n" . > "<h1>Hallo</h1>\n" . > "<p>Hier ist ein Text mit einem Bild:</p>\n" . > "<p><img alt='TB Logo' src='cid:$tb_logo_cid'></p>\n" . > "<p>Es funktioniert! <img alt=':-)' src='cid:$smiley_cid'></p>\n", > ); > > my $part = MIME::Lite->new( > Type => 'image/png', > Path => 'Mozilla_Thunderbird_logo.png', > ); > $part->attr('Content-Id', "<$tb_logo_cid>"); > $msg->attach($part); > > $part = MIME::Lite->new( > Type => 'image/gif', > Path => 'smiley16.gif', > ); > $part->attr('Content-Id', "<$smiley_cid>"); > $msg->attach($part); > > $msg->print(\*STDOUT); > __END__ > > hp OK, I am beginning to suspect there is a bug in Email::MIME somewhere. I know the files I am using to make the email are OK, since, if I replace the content of the email you construct in your example, and send it from my exchange server, the result is perfect except that it is sent from the wrong email address. The email address that should be used exists only on the gmail account I have been trying to use. I can send email using the following, but the image is cut in half: use strict; use warnings; use Email::MIME::CreateHTML; use Email::Sender::Transport::SMTP::TLS; #example modified so that there is text after image as well as before it my $html = qq{ <html><head><title>My Document</title></head><body> <p>Here is a picture:</p><img src="cid:logo.jpg"></p><p>qwerty qwerty</p> </body></html> }; my %objects = ( "logo.jpg" => "template.files/image002.jpg" ); my $quick_to_assemble_mime = Email::MIME->create_html( header => [ From => 'YYYYYYYYYYYYYYYYYYYYYYY', To => 'ZZZZZZZZZZZZZZZZZZZZZZZZZZZZ', Subject => 'My speedy HTML', ], body => $html, embed => 0, #<-- inline_css => 0, #<-- objects => \%objects #<-- ); my $sender = Email::Sender::Transport::SMTP::TLS->new( host => 'smtp.gmail.com', port => 587, username => 'YYYYYYYYYYYYYYYYYYYYYYY', password => 'XXXXXXXXXXXXX', ); eval { $sender->send($quick_to_assemble_mime, { from => 'YYYYYYYYYYYYYYYYYYYYYYY', to => [ 'ZZZZZZZZZZZZZZZZZZZZZZZZZZZZ' ], } ); } or die "Error sending email: $@"; In fact, if I tell it to use the png version of the logo, the image does not display at all, and instead, if I select it from thelist of attachments to view it, I get an error message that it is damaged. But the original file as it exists on my machine is perfect. What else can it be but Email::MIME->create_html (or rather the Email::MIME package it uses) breaking my graphics files? We know that it isn't the link between the html and the jpg file that is broken, because the part of the jpg that is maintained appears in the right place. Rather, it must be a problem with how it is handling the binary data in the jpg (and png file). I am stuck with two options, each of which has a show stopper problem. If I use MIME::Lite, I can't connect to gmail in order to send the email from the right email address, and if I use Email::MIME- >create_html, my graphics files are damaged (as sent within the email). I will be content if I can have a viable solution to either so that at least I can assemble and send the emails. Thanks Ted |