To learn how to save HTML emails please see article
[](http://wpcubed.com/forum/viewtopic.php?p=3287#3287)
How to load HTML and fetch the images:
WPTools will not create a connection to the internet to download images. It will create the events OnRequestHTTPImage for each IMG it finds and you can use Indy or Synapse to download the image from the web.
The event OnRequestHTTPImage should be used to load the images when the HTML reader comes to the IMG tag. That also works with RTF files which have linked images!
The key line in the event handler is
TextObject.LoadObjFromStream(URL,stream);
Example - using Indy9:
procedure TForm1.WPRichText1RequestHTTPImage(RTFData: TWPRTFDataCollection; Reader: TWPCustomTextReader; const LoadPath, URL: String; TextObject: TWPTextObj; var Ok: Boolean);var stream : TMemoryStream; loadurl : string;begin if pos('http:',lowercase(URL))>0 then loadurl := URL else loadurl := LoadPath + URL; stream := TMemoryStream.Create; try Panel2.Caption := URL; try Application.ProcessMessages; IdHTTP1.Get(loadurl,stream); except on e : Exception do Panel2.Caption := URL + '-->' + e.Message; end; if stream.Size>0 then try TextObject.LoadObjFromStream(URL,stream); except on e : Exception do Panel2.Caption := URL + '-->' + e.Message; end; ok := TRUE; if ok then Panel2.Caption := ''; Application.ProcessMessages; finally stream.Free; end;end;
I was not so happy with the loads of exceptions Indy produced and so didn't persue this further. But the handler itself is correct.
BTW - the CSS includes can be loaded using in OnRequestHTTPString - this was the code to do it:
procedure TForm1.WPRichText1RequestHTTPString(
RTFData: TWPRTFDataCollection; Reader: TWPCustomTextReader;
const LoadPath, URL: String; var LoadedString: String; var Ok: Boolean);
var loadurl : string;
begin
if pos('http:',lowercase(URL))>0 then
loadurl := URL
else loadurl := LoadPath + URL;
Panel2.Caption := URL;
Application.ProcessMessages;
LoadedString := IdHTTP1.Get(loadurl);
Ok := TRUE;
Panel2.Caption := '';
Application.ProcessMessages;
end;
Also, how do I save the edited RTF data from the TWPRichText control as an HTML file, along with all referenced embedded IMG tags?