Reputation: 640
I need to send an email to gmail with some inline images.
I use perl and MIME:LITE, but Gmail shows my image as Attachment, not inline.
What's the problem?
This is my code,
use MIME::Lite;
my $texto = '<html><body>hola <img src="cid:image" /> adios </body></html>';
#
my $msg = MIME::Lite->new(
Date => "Xxx, 22 Oct 2012 17:45:00 CET",
From => "[email protected]",
To => '[email protected]',
Subject => "En un lugar de la mancha",
'Message-ID' => '123456789012345656789@8888888888888ldkf',
Type =>'multipart/related'
);
$msg->attach(
Type => 'text/html',
Data => $texto,
Encoding => 'quoted-printable'
);
$msg->attach(
Encoding => 'base64',
Type => 'image/png',
Path => "image.png",
Id => "image"
);
$msg->scrub(['x-mailer', 'Content-Disposition']);
print $msg->as_string;
The result is this email (I strip image secction)
Content-Transfer-Encoding: binary
Content-Type: multipart/related; boundary="_----------=_135100636840600"
MIME-Version: 1.0
Date: Xxx, 22 Oct 2012 17:45:00 CET
From: pruebachunga.com
To: [email protected]
Subject: En un lugar de la mancha
Message-Id: 123456789012345656789@8888888888888ldkf
This is a multi-part message in MIME format.
--_----------=_135100636840600
Content-Transfer-Encoding: quoted-printable
Content-Type: text/html
<html><body>hola <img src=3D"cid:image" /> adios </body></html>=
--_----------=_135100636840600
Content-Id: <image>
Content-Transfer-Encoding: base64
Content-Type: image/png; name="image.png"
iVBORw0KGgoAAAANSUhEUgAAAGQAAABkCAMAAAEwO1XwAAAAB3RJTUUH1gYE
...
kmqg1wGgkx35p/KStnLuw2BGhXwIZqT+D8sxTLVK0VpuAAAAAElFTkSuQmCC
--_----------=_135100636840600--
EDIT:
After reading on the web, I think that image is an attachment and has a problem known as "Image Blocking": https://www.campaignmonitor.com/resources/guides/image-blocking-in-email/
I maintained my question because people may find this question interesting. Now, I think that this code is correct, and with the other message, other ID, other sender... this code can run well.
Upvotes: 0
Views: 6722
Reputation: 640
After reading on the web, I think that image is an attachment and has a problem known as "Image Blocking": https://www.campaignmonitor.com/resources/guides/image-blocking-in-email/
I maintained my question because people may find this question interesting. Now, I think that this code is correct, and with the other message, other ID, other sender... this code can run well.
Upvotes: 1
Reputation: 867
I use external variant.
my $mailHTML = new MIME::Lite::HTML
From => $i_from,
To => $i_to,
Subject => $i_subj,
IncludeType => 'extern',
HTMLCharset => 'utf-8';
In this case, you need specify in HTML like
<img src="http://external_url/to_image">
http or https!
Upvotes: -1
Reputation: 116177
You should not scrub 'Content-Disposition' field - it is important!
MIME::Lite is using inline content disposition by default, but you can also set it explicitly
$msg->attach(
Encoding => 'base64',
Type => 'image/png',
Path => 'image.png',
Id => 'image',
Disposition => 'inline',
);
and it should all work.
Upvotes: 1