trichview.com

trichview.support




Re: Creating an email compatable image


Return to index


Author

Message

Sergey Tkachenko

Posted: 07/08/2003 22:44:37


Below is a copy of two postings on this topic.

They use Indy, but I think it's not very difficult to encode images yourself

and append them to the html file



=========== 1 ==================

Wm David Parker wrote


following code snippet uses 3 Indy components to email (via SMTP) a

RichViewEdit file containing embedded images:


procedure TForm1.bTestClick(Sender: TObject);

//Drop the following Indy9 components

//on Unit1 in the RvEditDemo.DPR project (no special property values):

//  IdMessage: TIdMessage;

//  IdAntiFreeze: TIdAntiFreeze;

//  IdSMTP: TIdSMTP;

//interface uses must include: IdTCPClient, IdMessageClient, IdSMTP,

IdStack;

var

  TmpList: TStringList;

  APlainPart: TIdText;

  AHtmlPart: TIdText;

  ImageName: string;

  Cnt: integer;

begin try

  Screen.Cursor := crHourglass;

  RichViewEdit1.SaveHTML('HtmlTest.htm', 'Demo File', 'img',

[rvsoOverrideImages]);


  TmpList := TStringList.Create;

  TmpList.LoadFromFile('HtmlTest.htm');


  APlainPart := TIdText.Create(IdMessage.MessageParts);

  APlainPart.ContentType := 'text/plain';

  APlainPart.Body.Text := 'This is a plain text message part.';


  AHtmlPart := TIdText.Create(IdMessage.MessageParts);

  AHtmlPart.ContentType := 'text/html';

  AHtmlPart.Body.Text := TmpList.Text;


  for Cnt := 0 to pred(RichViewEdit1.ImgSaveNo) do begin

    ImageName := 'img' +IntToStr(Cnt+1) +'.jpg';

    //From Borland...WinSock news group by Geoff Os - 10/4/2002 5pm

    //Not sure what Content-ID does


TIdAttachment.Create(IdMessage.MessageParts,ExtractFilePath(Application.EXEN

ame)

        + ImageName).ExtraHeaders.Values['Content-ID'] := ImageName;

    end;


  IdMessage.From.Text := 'Dave';

  IdMessage.Recipients.EMailAddresses := '[email protected]';

  IdMessage.Subject := 'HtmlTest w/images';

  IdMessage.ContentType := 'multipart/alternative';


  try

    IdSMTP.Host := GStack.ResolveHost('www.DelphiExpert.com'); //Same as

'128.242.87.41'

    IdSMTP.Connect;

    IdSMTP.Send(IdMessage);

  finally

    IdSMTP.Disconnect;

  end;

  finally

    Screen.Cursor := crDefault;

  end; end;



============== 2 =========


Sergey Tkachenko wrote:


About creating HTML e-mails:


As I understand, links to images in MIME e-mail must start with 'cid:', for

example

<IMG src='cid:img1.jpg'>

where img1.jpg is a content-id (in this example they are always equal to

file names).

It looks like Outlook Express understands links even without 'cid:' for

images, but it does not understand them for HTML background.


The code below can be assigned to OnHTMLSaveImage event. It adds 'cid:' in

HTML image links.

It assumes:

  a.. document has no image-list bullets, hotspots and list markers linked

to image-list; if they present, you need to draw them in a temporal bitmap

and then save just like gr in this example;

  b.. the latest version of RichView (with table and cell background images)

is used

  c.. default image saving (as jpegs)

This code is not tested.


uses RVItem, RVTable, CRVData, RVMarker;


procedure TForm3.RichViewEdit1HTMLSaveImage(Sender: TCustomRichView;

  RVData: TCustomRVData; ItemNo: Integer; const Path: String;

  BackgroundColor: TColor; var Location: String; var DoDefault: Boolean);

var gr: TGraphic;

  Tag: Integer;

  VAlign: TRVVAlign;

  Name: String;

begin

  gr := nil;

  if ItemNo<0 then begin

    if RVData is TRVTableCellData then

      gr := TRVTableCellData(RVData).BackgroundImage

    else

      gr := Sender.BackgroundBitmap;

    end

  else

    case RVData.GetItemStyle(ItemNo) of

      rvsPicture, rvsHotPicture:

        gr := TRVGraphicItemInfo(RVData.GetItem(ItemNo)).Image;

      rvsListMarker:

        gr :=

TRVMarkerItemInfo(RVData.GetItem(ItemNo)).GetLevelInfo(Sender.Style).Picture

.Graphic;

      rvsTable:

        gr := TRVTableItemInfo(RVData.GetItem(ItemNo)).BackgroundImage;

    end;

  if gr<>nil then begin

    Location := 'cid:'+RVData.SavePicture(rvsfHTML, 'img', Path,

Sender.ImgSaveNo, True, BackgroundColor, gr);

    DoDefault := False;

  end;

end;




> I would like to embed an image in the HTML file produced by RV so that

> it could be emailed.  Is this possible?

>

> Currently, I pass the URL of the image, however I have to then place the

> image on the server.

>

> Todd

>







Powered by ABC Amber Outlook Express Converter