通过电子邮件发送StringList作为附件 - Indy

时间:2012-12-04 11:22:08

标签: delphi delphi-xe2 indy10

如何通过电子邮件发送整个StringList而不保存到硬盘?我知道附件限制..

3 个答案:

答案 0 :(得分:5)

您可以使用TIdAttachmentMemory代替TIdAttachmentFile:

StringList := TStringList.Create;
StringList.Append('foo');
StringList.Append('bar');

MemoryStream := TMemoryStream.Create;
StringList.SaveToStream(MemoryStream);
MemoryStream.Position := 0;

IdMessage := TIdMessage.Create(nil);
IdAttachmentMemory := TIdAttachmentMemory.Create(IdMessage.MessageParts,MemoryStream);

答案 1 :(得分:2)

您可以使用 StringList.Text 属性。此属性可用于读取和写入,从而将字符串列表的内容作为字符串参数传递(而不是尝试传递对象)。

答案 2 :(得分:0)

为什么不将它保存到文件并将文件作为附件发送?