[Demo] Sending HTML email. Saving MIME-encoded files.

Demos, code samples. Only questions related to the existing topics are allowed here.
Sergey Tkachenko
Site Admin
Posts: 17522
Joined: Sat Aug 27, 2005 10:28 am
Contact:

Post by Sergey Tkachenko »

Process OnWriteHyperlink event.
In this event, write:
Target := PChar(RVData.GetItemTag(ItemNo));
Make sure that rvoTagsArePChars is included in Options.

Update 2011-Oct-22:
For TRichView 13.3+, the code should be
Target := RVData.GetItemTag(ItemNo);
And rvoTagsArePChars is obsolete and does nothing.
Sergey Tkachenko
Site Admin
Posts: 17522
Joined: Sat Aug 27, 2005 10:28 am
Contact:

Post by Sergey Tkachenko »

A new demo using Indy is added (in Delphi\Indy folder).
The old demo was moved to Delphi\Indy.old.

Old demo:
This demo tricks Indy. Indy thinks that this is a plain text message, but the demo includes all HTML email codes in the plain text, so it is actually an HTML email.
This demo can be used with all versions of Indy (may be with some minor modifications) and Delphi. It requires thirdparty code (included) for base64 encoding.

New demo:
This demo uses Indy features to create an HTML email. It requires Indy 10+ (because Indy 9 did not allow nested mime sections, required for HTML emails).
This demo requires Delphi 2009 or newer (it was created in Delphi XE2)
Note: the new version of Indy allows creating HTML email even more easily, using TIdMessageBuilderHtml. I was not aware about this class when creating this demo. Nevertheless, the results of this demo and of TIdMessageBuilderHtml must be identical.
PioPio
Posts: 41
Joined: Mon Feb 18, 2013 4:21 pm

Post by PioPio »

Sergey Tkachenko wrote:A new demo using Indy is added (in Delphi\Indy folder).

New demo:
This demo uses Indy features to create an HTML email. It requires Indy 10+ (because Indy 9 did not allow nested mime sections, required for HTML emails).
This demo requires Delphi 2009 or newer (it was created in Delphi XE2)
Note: the new version of Indy allows creating HTML email even more easily, using TIdMessageBuilderHtml. I was not aware about this class when creating this demo. Nevertheless, the results of this demo and of TIdMessageBuilderHtml must be identical.
I ran this example but it seems the email sent doesn't take into account the Font name and the attributes, Bold, Italic, Underline (I haven't checked the alignment options).

Is there a way to fix this ?

Many thanks

Pio Pio
Sergey Tkachenko
Site Admin
Posts: 17522
Joined: Sat Aug 27, 2005 10:28 am
Contact:

Post by Sergey Tkachenko »

All font attributes must be taken into account.
Please send me step-by-step instructions how to reproduce the problem.
PioPio
Posts: 41
Joined: Mon Feb 18, 2013 4:21 pm

Post by PioPio »

Sergey Tkachenko wrote:All font attributes must be taken into account.
Please send me step-by-step instructions how to reproduce the problem.
Hello Sergey,

I opened the example SendMail in the folder Indy and ran it. The email was sent successfully but the text is in Comic Sans MS in TRichViewEdit1 and in the email is a different one.

I made then another test, amended TVStyle.TextStyles[1].size=20 and ran the example again. The email was sent successfully again but the size didn't change in the email.

Many thanks


Pio Pio
Sergey Tkachenko
Site Admin
Posts: 17522
Joined: Sat Aug 27, 2005 10:28 am
Contact:

Post by Sergey Tkachenko »

Please run this demo and send a test email to richviewgmailcom
PioPio
Posts: 41
Joined: Mon Feb 18, 2013 4:21 pm

Post by PioPio »

Sergey Tkachenko wrote:Please run this demo and send a test email to richviewgmailcom
Message was sent.

Thanks and regards,


Pio Pio
Sergey Tkachenko
Site Admin
Posts: 17522
Joined: Sat Aug 27, 2005 10:28 am
Contact:

Post by Sergey Tkachenko »

I think I should post an answer here too.

TRichView.SaveHTMLToStreamEx uses named CSS classes to produce a clean and compact HTML code. Such HTML is shown correctly in desktop email clients. However, many online email clients (including the most popular ones) have problems with such HTML code - text and paragraph attributes are lost.

Solution:
1) Use SaveHTMLToStream instead of SaveHtmlToStreamEx. It produces basic HTML code without CSS.
Cons: only basic text and paragraph attributes are supported.
or
2) Include rvsoInlineCSS in the Options parameter of SaveHtmlToStreamEx. This will produce much larger HTML code, however, the problem will be solved.
MagicTom
Posts: 3
Joined: Thu Sep 15, 2005 4:44 am

Mail in Database

Post by MagicTom »

Hello Sergey,
how would save the received mails in a database or write a new mail to a database?

Thomas
Sergey Tkachenko
Site Admin
Posts: 17522
Joined: Sat Aug 27, 2005 10:28 am
Contact:

Post by Sergey Tkachenko »

Sorry, these tasks are beyond the scope of our demos.
This demo only shows how to convert TRichViewEdit content to HTML email, and how to send this email using Indy.
It does not even show how to load HTML email in TRichViewEdit.

A very simple but functional email client demo is created using CleverComponents: http://www.trichview.com/forums/viewtopic.php?t=4123
Sergey Tkachenko
Site Admin
Posts: 17522
Joined: Sat Aug 27, 2005 10:28 am
Contact:

Re: [Demo] Sending HTML email. Saving MIME-encoded files.

Post by Sergey Tkachenko »

The demos were updated for compatibility with TRichView 17.3.
Now they use functions included in TRVGraphicHandler class, so the code is slightly simplified.
The demos include a newer version of DMime (2.8). It is compatible with RAD Studio 10.2 Tokyo. DMime is used to implement base64 encoding in Delphi\SaveFile and Delphi\Indy.old demos.

C++Builder demo for saving MHT and EML files is reworked. Previously, this demo was for C++Builder 6 and 2007.
Now, it is for C++Builder XE7 and newer. Unlike the Delphi version of this demo, it does not use DMime, but uses functions from standard System.NetEncoding unit.
Post Reply