Re: adding an image to an email

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

"John Evans" <johneva…@clear-Advantage.co.uk> wrote in message
news:C7B7632A0FC7E240johneva…@clear-Advantage.co.uk...

>        with TIdAttachment.Create(email.MessageParts, PictureFilename  )
do
>        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
    begin
        ContentID := 'SomeUniqueValueForThisFile';
        ContentType := GetMimeTypeFromFile(PictureFilename);
    end;

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.

Gambit

Replies

In response to

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