4

我正在尝试使用 indy 9 发送电子邮件:

  • 正文为 RTF,从 TRichEdit 格式化
  • 附上一个文件

编码:

 Message := TIdMessage.Create()
 Message.Recipients.EMailAddresses := 'someone@domain.dotcom';

 Message.ContentType := 'multipart/alternative';

 with TIdText.Create(Message.MessageParts) do
   ContentType := 'text/plain';

 with TIdText.Create(Message.MessageParts) do
 begin
   ContentType := 'text/richtext';
   Body.LoadFromFile('c:\bodymsg.rtf');
 end;

 TIdAttachment.Create(Message.MessageParts, 'c:\myattachment.zip');

 // send...

结果:正文为空(使用 web gmail 和 Outlook 2010 作为客户端)。

我已经尝试过其他内容类型但没有成功:

  • 文本/rtf
  • 文本/丰富

注意:我不会升级到 Indy 10。

4

1 回答 1

5

存在时,您将 设置TIdMessage.ContentType为错误的值TIdAttachment。需要将其设置为,'multipart/mixed'因为您在同一顶级 MIME 嵌套级别将'multipart/alternative'和部分混合在一起,而这些部分是该部分的子代。'application/x-zip-compressed''text/...''multipart/alternative'

看看我在 Indy 网站上写的以下博客文章:

HTML 消息

您尝试创建的电子邮件结构包含在“纯文本和 HTML 和附件:仅非相关附件”部分中。您只需将 HTML 替换为 RTF,并忽略该部分的TIdText对象,'multipart/alternative'因为TIdMessage在 Indy 9 中将在内部为您创建该对象(在 Indy 10 中明确需要它,因为它比 Indy 9 具有更深的 MIME 支持)。

试试这个:

Message := TIdMessage.Create()
Message.Recipients.EMailAddresses := 'someone@domain.dotcom';

Message.ContentType := 'multipart/mixed';

with TIdText.Create(Message.MessageParts) do
begin
  ContentType := 'text/plain';
  Body.Text := 'You need an RTF reader to view this message';
end;

with TIdText.Create(Message.MessageParts) do
begin
  ContentType := 'text/richtext';
  Body.LoadFromFile('c:\bodymsg.rtf');
end;

TIdAttachment.Create(Message.MessageParts, 'c:\myattachment.zip');

// send...
于 2013-03-13T22:12:33.783 回答