gpt4 book ai didi

delphi - Indy 9 - 正文为 RTF 并带有附件的电子邮件

转载 作者:行者123 更新时间:2023-12-03 15:50:27 26 4
gpt4 key购买 nike

我正在尝试使用 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...

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

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

  • 文本/rtf
  • 文本/丰富

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

最佳答案

当存在 TIdAttachment 时,您将 TIdMessage.ContentType 设置为错误的值。它需要设置为 'multipart/mixed' 因为您正在混合 'multipart/alternative''application/x-zip-compressed' 部分位于同一顶级 MIME 嵌套级别,而 'text/...' 部分是 'multipart/alternative' 部分的子级.

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

HTML Messages

“纯文本和 HTML 及附件:仅限非相关附件”部分涵盖了您尝试创建的电子邮件结构。您只需将 HTML 替换为 RTF,并忽略 'multipart/alternative' 部分的 TIdText 对象,因为 Indy 9 中的 TIdMessage 将创建该对象在内部为您提供(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...

关于delphi - Indy 9 - 正文为 RTF 并带有附件的电子邮件,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/15395183/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com