在delphi中发送带有rtf文本的电子邮件 [英] Send an e-mail with rtf text in delphi

查看:188
本文介绍了在delphi中发送带有rtf文本的电子邮件的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想执行以下任务:将TRichEdit内容(rtf文本)转换为不明文本的电子邮件正文。



MAPI不支持rtf,但是有没有办法这样做可能与Indy?



问题是rtf是rtf和电子邮件是纯文本或HTML。 p>

有人可以提出一个伎俩吗?是否可以使用TWebBrowser将rtf转换为文本?



基本上该方案是:

1)用户以delphi格式写入电子邮件,

2)然后,电子邮件与MAPI一起发送到默认邮件客户端(因此生成一个新的电子邮件窗口,邮件正文与delphi格式相同)

3)用户从邮件客户端发送电子邮件



无论如何,MAPI只接受纯文本。



更新:



尝试与Indy我写这个,但仍然没有工作,因为我发送邮件到我的Gmail帐户,我收到一个消息与空的身体和NONAME假附件。

 使用IdMessageBuilder; 


程序SendMail;
var
MBuilder:TIdMessageBuilderRtf;
MyMemoryStream:TMemoryStream;
begin
try
MBuilder:= TIdMessageBuilderRtf.Create;
MyMemoryStream:= TMemoryStream.Create;
MBuilder.RtfType:= idMsgBldrRtfRichtext;
// RichEdit1在设计时将PlainText设置为False
//我将一些格式化文本粘贴到
RichEdit1.Lines.SaveToStream(MyMemoryStream);
MBuilder.Rtf.LoadFromStream(MyMemoryStream);
MBuilder.FillMessage(IdMessage1);
IdSMTP1.Connect;
IdSMTP1.Send(IdMessage1);
IdSMTP1.Disconnect;
finally
MyMemoryStream.Free;
MBuilder.Free;
结束
结束


解决方案

Indy支持发送RTF电子邮件。发送电子邮件的方式与发送HTML电子邮件的方法相同,只需使用text / rtf,text / enrich或text / richtextContext-Type,然后发送由TRichEdit生成的原始RTF代码其PlainText属性设置为false。另外,如果您使用Indy 10,请查看其TIdMessageBuilderRtf类来正确设置TIdMessage结构。


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;

解决方案

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.

这篇关于在delphi中发送带有rtf文本的电子邮件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆