From: Ted Byers on
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
From: Ted Byers on
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
From: Ted Byers on
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
From: Peter J. Holzer on
On 2010-06-21 15:42, Ted Byers <r.ted.byers(a)gmail.com> wrote:
> 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.

Your script works for me. I get an email which I can display in
thunderbird. A image which is only partially displayed looks like an
encoding problem to me. Are you running on Windows? If so, it is
possible that Email::MIME::CreateHTML doesn't open the image properly in
binary mode (on Unixes there is no difference, so such a bug might go
undetected).

hp