html email with pics

General TRichView support forum. Please post your questions here
Post Reply
Lucian
Posts: 56
Joined: Fri Aug 01, 2014 9:52 am

html email with pics

Post by Lucian »

Hi,

I am trying to send an html email with a picture in the body of the email and the picture is transformed in an attachment. Is this normal?

For this, I am using TRVReportHelper, TRvHtmlImporter, TRichView. Code is something like this:

lRVHelper:= TRVReportHelper.Create(nil);
lRVHtmlImporter := TRvHtmlImporter.Create(nil);
lRVHtmlImporter.RichView := lRVHelper.RichView;
...
SaveOptions := [rvsoOverrideImages];
FileName := Format('%sph_mail.html', [sMailDir]);
lRVHelper.RichView.SaveHTML(FileName, '', 'htmlimage', SaveOptions);

... and from here I grab the file and the eventual images and use Indy to send an email, something like this:

MB := TIdMessageBuilderHtml.Create;
TIdMessageBuilderHtml(MB).Html.Text := MailBody;
if imgs <> nil then
for i := 0 to imgs.Count - 1 do
TIdMessageBuilderHtml(MB).HtmlFiles.Add(imgs);
AddAttachments(MB);


My boss wants to get the picture in the body of the email, like it was when the message was created in TRichView. Is this possbile?
Sergey Tkachenko
Site Admin
Posts: 17565
Joined: Sat Aug 27, 2005 10:28 am
Contact:

Post by Sergey Tkachenko »

Sorry, I do not have an example building email using TIdMessageBuilderHtml.

The example of building HTML email using TIdText and TIdAttachmentMemory parts can be found here:
http://www.trichview.com/support/files/mime.zip
(in Delphi\Indy\ folder)
Lucian
Posts: 56
Joined: Fri Aug 01, 2014 9:52 am

Post by Lucian »

The problem is not with Indy, I am not asking about that. The problem is with RichView.SaveHTML method which saves images in external files. I am asking if there's a way of saving the html file, without using external files (might be a silly question, but I never had any interests in learning html, so I don't know if that's even possible). Something like a <BINARY> tag, the way PDF format supports saving image content in the pdf itself.

Because the images are saved in external files, they must be attached, and so, the program that receives the email, has the picture as an attachment, but the picture was in the body when the message was created.... I hope it's clear now.
Sergey Tkachenko
Site Admin
Posts: 17565
Joined: Sat Aug 27, 2005 10:28 am
Contact:

Post by Sergey Tkachenko »

Please look in the code:
http://www.trichview.com/support/files/mime.zip
(in Delphi\Indy\ folder)
It solves all these problems.

This demo uses OnSaveImage2 event to store images in memory (in a collection) instead of files, and providing 'cid:' links for <img src>. Later, these images are saved as TIdAttachmentMemory.

Please note that images and attached files are saved in different places of HTML email. It is important!
Generally, nesting structure of HTML email containing all parts is the following:
(((text HTML) image1 image2 ...) file1 file2 ...)
All parts must have correct content type.
For (text HTML): ContentType := 'multipart/alternative'.
For part combining (text HTML) and images: ContentType := 'multipart/related; type="multipart/alternative"'.
For the whole message: ContentType := 'multipart/mixed'.
If the message does not have attachments or images, some parts are not needed.

You can use the ready-to-use code from that demo, or can try to create your code using TIdMessageBuilderHtml.
Lucian
Posts: 56
Joined: Fri Aug 01, 2014 9:52 am

Thank you very much

Post by Lucian »

I'll check the sample.
Post Reply