[DUG] Problem embedding images in html formated email using Indy 10
Mike Stokes
mike at webdata.co.nz
Thu Feb 15 15:16:18 NZDT 2007
Hello every one.
I am having a great deal of trouble trying to embed images using cid to
reference the attached jpeg image.
This is some test code that sends the html formatted email with the
attached image, but does not display the image in line.
I have been using Thunderbird 1.5.0.9 to test this.
Regards,
Mike
procedure TForm1.Button1Click(Sender: TObject);
var
IdAttach: TIdAttachmentFile;
IdText1: TIdText;
IdText2: TIdText;
begin
IdSMTP.Host := 'smtp.maxnet.co.nz';
IdSMTP.Port := 25;
IdSMTP.Username := '';
IdSMTP.Password := '';
IdMessage.From.Address := 'mike at webdata.co.nz';
IdMessage.Recipients.EMailAddresses := 'mike at webdata.co.nz';
IdMessage.Subject := 'test';
IdMessage.Sender.Address := 'mike at webdata.co.nz';
IdMessage.ContentType := 'multipart/mixed';
IdMessage.Body.Add('<html>');
IdMessage.Body.Add('<head></head>');
IdMessage.Body.Add('<body>');
IdMessage.Body.Add('<br /><br /><span
style="color:red;font-weight:bold;">Here is the image:</span><br /><br
/><br />');
IdMessage.Body.Add('<img src="cid:sm101yellow.jpg" />');
IdMessage.Body.Add('</body>');
IdMessage.Body.Add('</html>');
IdText1 := TIdText.Create(IdMessage.MessageParts, IdMessage.Body);
IdText1.ContentType := 'text/html';
IdText2 := TIdText.Create(IdMessage.MessageParts);
IdText2.ContentType := 'text/plain';
IdText2.Body.Text := '';
IdAttach := TIdAttachmentFile.Create(IdMessage.MessageParts,
'd:\sm101yellow.jpg');
IdAttach.ContentType := 'image/jpeg';
IdAttach.ContentDisposition := 'inline';
IdAttach.ContentID := 'sm101yellow.jpg';
IdAttach.DisplayName := 'sm101yellow.jpg';
try
try
IdSMTP.Connect;
IdSMTP.Send(IdMessage);
except
on E:Exception do
ShowMessage('Failed to send Email!'+#13#10+e.message);
end;
finally
if IdSMTP.Connected then
IdSMTP.Disconnect;
end;
Showmessage('Email Sent');
end;
More information about the Delphi
mailing list