[Demo] Sending HTML email. Saving MIME-encoded files.
-
- Site Admin
- Posts: 17571
- Joined: Sat Aug 27, 2005 10:28 am
- Contact:
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.
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.
-
- Site Admin
- Posts: 17571
- Joined: Sat Aug 27, 2005 10:28 am
- Contact:
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.
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.
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).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.
Is there a way to fix this ?
Many thanks
Pio Pio
-
- Site Admin
- Posts: 17571
- Joined: Sat Aug 27, 2005 10:28 am
- Contact:
Hello Sergey,Sergey Tkachenko wrote:All font attributes must be taken into account.
Please send me step-by-step instructions how to reproduce the problem.
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
-
- Site Admin
- Posts: 17571
- Joined: Sat Aug 27, 2005 10:28 am
- Contact:
-
- Site Admin
- Posts: 17571
- Joined: Sat Aug 27, 2005 10:28 am
- Contact:
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.
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.
Mail in Database
Hello Sergey,
how would save the received mails in a database or write a new mail to a database?
Thomas
how would save the received mails in a database or write a new mail to a database?
Thomas
-
- Site Admin
- Posts: 17571
- Joined: Sat Aug 27, 2005 10:28 am
- Contact:
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
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
-
- Site Admin
- Posts: 17571
- Joined: Sat Aug 27, 2005 10:28 am
- Contact:
Re: [Demo] Sending HTML email. Saving MIME-encoded files.
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.
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.