Send StringList as Attachment via Email - Indy

delphi, delphi-xe2, indy10

Solution

You can use TIdAttachmentMemory instead of 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);

Problem

How can I send whole StringList via attachment through Email without saving to the harddrive? I am aware of attachment limits..

Original source