Newsgroups : Borland : borland.public.delphi.internet.winsock : 2005 Jun : HTML Emails and Indy 10
| Subject: | HTML Emails and Indy 10 |
| Posted by: | "Tim Sullivan" (tim@no.spam.uil.for.me.net) |
| Date: | Mon, 20 Jun 2005 17:34:50 |
I'm in the process of updating my email code, and I'm trying to have HTML
emails with embedded (related) images. I've found a number of articles that
explain the process on tamaracka.com and I'm pretty sure I've got this all
set up correctly, but for some reason the email, when it arrives, is
visually empty - no text part, no html message, nothing. The content of the
email is clearly coming through, since I see it downloading the 160K or so
that the message is supposed to be.
I'm using Delphi 7 and Indy 10.0.52.
Here is the code that is generating the IdMessage:
procedure TEmailBuilder.BuildHTMLAndEmbedded(AMessage: TIdMessage);
var
j : Integer;
begin
AMessage.ContentType := 'multipart/alternative';
// Create plain text part
with TIdText.Create(AMessage.MessageParts, FTextMessage) do
ContentType := 'text/plain';
// create part to hold html and attachments
with TIdText.Create(AMessage.MessageParts) do
ContentType := 'multipart/related';
with TIdText.Create(AMessage.MessageParts, FBody) do
begin
ContentType := 'text/html';
ParentPart := 1;
end;
// Create embedded attachments
for j := 0 to FEmbeddedAttach.Count - 1 do
begin
with TIdAttachmentFile.Create(AMessage.MessageParts,
FEmbeddedAttach[j]) do
begin
ContentType := GetMimeTypeFromFile(FEmbeddedAttach[j]);
ParentPart := 1;
end; // with
end;
end;
The email that is sent looks like this:
Subject: testing testing!
To: tim@uil.net
Content-Type: multipart/alternative;
boundary="KywwqE3vN7MgA56La1Y1xP8=_MxVKriNbv"
MIME-Version: 1.0
Sender: Tim Sullivan <tim@uil.net>
Organization: Questek Systems, Inc.
Date: Mon, 20 Jun 2005 15:53:32 -0400
This is a multi-part message in MIME format
--KywwqE3vN7MgA56La1Y1xP8=_MxVKriNbv
Content-Type: text/plain
Content-Transfer-Encoding: quoted-printable
This is an HTML message, and requires an HTML-enabled mail client to r=
ead it.
--KywwqE3vN7MgA56La1Y1xP8=_MxVKriNbv
Content-Type: multipart/related;
boundary="KywwqE3vN7MgA56La1Y1xP8=_MxVKriNbvS"
--KywwqE3vN7MgA56La1Y1xP8=_MxVKriNbvS
Content-Type: text/html
Content-Transfer-Encoding: quoted-printable
<html>
<body>
<p>
This is test with images.
</p>
<p>
<img src="cid:barker2.gif" align="left"
alt="" />
</p>
</body>
</html>
--KywwqE3vN7MgA56La1Y1xP8=_MxVKriNbvS
xContent-Type: image/gif;
name="barker2.gif"
xContent-Transfer-Encoding: base64
xContent-Disposition: attachment;
filename="barker2.gif"
[bunch of encoded stuff removed - x put in front of some headers because the
Borland news server rejected the message :-)]
--KywwqE3vN7MgA56La1Y1xP8=_MxVKriNbvS--
--KywwqE3vN7MgA56La1Y1xP8=_MxVKriNbv--
Thanks in advance for any assistance. I'm quite sure I've got something
moronically wrong here, but I've just been beating my head against a wall
for a day now.
--
Tim Sullivan
Unlimited Intelligence Limited
http://www.uil.net