我正在尝试发送一封带有indy 9的电子邮件:
代码:
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...
Run Code Online (Sandbox Code Playgroud)
结果:正文为空(使用web gmail和outlook 2010作为客户端).
我已经尝试过其他内容类型而没有成功:
注意:我不会升级到Indy 10.
TIdMessage.ContentType当TIdAttachment存在时,您将设置为错误的值.它需要设置'multipart/mixed',而不是因为你是混合'multipart/alternative'和'application/x-zip-compressed'部分一起在同一个顶层MIME嵌套级别,而'text/...'部分是孩子们的'multipart/alternative'一部分,而不是.
看看我在Indy网站上写的以下博客文章:
您尝试创建的电子邮件结构包含在"纯文本和HTML和附件:仅与非相关的附件"部分中.您只需用RTF替换HTML,并忽略该部分的TIdText对象,'multipart/alternative'因为TIdMessageIndy 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...
Run Code Online (Sandbox Code Playgroud)