Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Send an e-mail with rtf text in delphi

I would like to perform the following task: converting a TRichEdit content (an rtf text) into a not-plain-text e-mail message body.

MAPI doesn't support rtf, but is there a way to do it maybe with Indy?

The problem is that rtf is rtf and emails are plain text or HTML.

Can someone suggest a trick? Is it possible to convert rtf to text using TWebBrowser?

Basically the scenario is:
1) User writes email in a delphi form,
2) The email is then sent with MAPI to the default mail client (so a new email window is generated, and the message body is the same I had in delphi form)
3) User sends the email from mail client

Anyway MAPI accepts only plain text.

UPDATE:

Trying with Indy I wrote this but still it doesn't work, as I send a mail it to my gmail account I recieve a message with empty body and NONAME fake attachment.

uses IdMessageBuilder;


procedure SendMail;
var
  MBuilder: TIdMessageBuilderRtf;
  MyMemoryStream: TMemoryStream;
begin
  try
    MBuilder := TIdMessageBuilderRtf.Create;
    MyMemoryStream := TMemoryStream.Create;
    MBuilder.RtfType := idMsgBldrRtfRichtext;
    // RichEdit1 has PlainText set to False
    // at design time I pasted some formatted text onto it
    RichEdit1.Lines.SaveToStream(MyMemoryStream);
    MBuilder.Rtf.LoadFromStream(MyMemoryStream);
    MBuilder.FillMessage(IdMessage1);
    IdSMTP1.Connect;
    IdSMTP1.Send(IdMessage1);
    IdSMTP1.Disconnect;
  finally
    MyMemoryStream.Free;
    MBuilder.Free;
  end;
end;
like image 272
LaBracca Avatar asked Jul 22 '10 13:07

LaBracca


People also ask

How do you send an RTF email?

On the File tab, choose Options > Mail. Under Compose messages, in the Compose messages in this format list, click HTML, Rich Text, or Plain Text.

What is an RTF email?

Rich Text EmailsRich text format (RTF) emails can be formatted, allowing for links, alignment and the use of bullet points. If you use Outlook, it automatically converts your rich text email to HTML when you send it to an Internet recipient.


1 Answers

Indy supports sending RTF emails. Send an email the same way you would send an HTML email, just use the "text/rtf", "text/enriched", or "text/richtext" Context-Type, and send the raw RTF codes that are generated by TRichEdit when its PlainText property is set to false. Also, if you are using Indy 10, look at its TIdMessageBuilderRtf class to set up the TIdMessage structure correctly.

like image 197
Remy Lebeau Avatar answered Oct 03 '22 22:10

Remy Lebeau