[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: 13472
Joined: Sat Aug 27, 2005 10:28 am
Contact:

Post by Sergey Tkachenko » Tue Sep 28, 2010 3:20 pm

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: 13472
Joined: Sat Aug 27, 2005 10:28 am
Contact:

Post by Sergey Tkachenko » Wed May 09, 2012 10:12 am

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 » Sat Mar 02, 2013 11:28 pm

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: 13472
Joined: Sat Aug 27, 2005 10:28 am
Contact:

Post by Sergey Tkachenko » Sun Mar 03, 2013 6:29 am

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 » Sun Mar 03, 2013 10:25 am

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: 13472
Joined: Sat Aug 27, 2005 10:28 am
Contact:

Post by Sergey Tkachenko » Sun Mar 03, 2013 12:28 pm

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 » Sun Mar 03, 2013 12:34 pm

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: 13472
Joined: Sat Aug 27, 2005 10:28 am
Contact:

Post by Sergey Tkachenko » Thu Mar 21, 2013 4:46 pm

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 » Sat Mar 22, 2014 11:54 am

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: 13472
Joined: Sat Aug 27, 2005 10:28 am
Contact:

Post by Sergey Tkachenko » Tue Mar 25, 2014 10:41 am

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

Post Reply