Re: adding an image to an email

Giganews Newsgroups
Subject: Re: adding an image to an email
Posted by:  Remy Lebeau (TeamB) (
Date: Thu, 14 Apr 2005

"John Evans" <johneva…> wrote in message

>        with TIdAttachment.Create(email.MessageParts, PictureFilename  )
>        begin
>          email.ContentType:='image/jpeg';
>        end;

You are setting the ContentType of the TIdMessage, not the TIdAttachment.
And you did not set the ContentID property of the TIdAttachment at all.  You
need to do so.  Otherwise, the HTML cannot find the image when displayed.

    with TIdAttachment.Create(email.MessageParts, PictureFilename) do
        ContentID := 'SomeUniqueValueForThisFile';
        ContentType := GetMimeTypeFromFile(PictureFilename);

Then the HTML references the image like this:

    <img src="cid:SomeUniqueValueForThisFile">

> My understanding from the help file is that I have to use
> TidAttachment for images.

Yes.  But you are only using it partially.  Setting the filename only is not
enough to make it available to HTML documents.



In response to

adding an image to an email posted by John Evans on Thu, 14 Apr 2005