Google Groups no longer supports new Usenet posts or subscriptions. Historical content remains viewable.
Dismiss

How to: Attachment From Stream in TIdAttachment Indy

325 views
Skip to first unread message

Carlos Guerra

unread,
Jul 23, 2004, 9:01:50 PM7/23/04
to
Hi all

Is it possible to create a file into an Stream and then try to send it as an
attachment with Indy TIdAttachment??

Thanks

Carlos


Remy Lebeau (TeamB)

unread,
Jul 24, 2004, 1:37:56 AM7/24/04
to

"Carlos Guerra" <cgu...@aduasys.com> wrote in message
news:4101b547$1...@newsgroups.borland.com...

> Is it possible to create a file into an Stream and then
> try to send it as an attachment with Indy TIdAttachment??

Not in Indy 9, no. It does not support streams as attachments, only files.

Indy 10 supports streams as attachments, as well as custom attachment type
since TIdAttachment is now a base class for other descendant classes.


Gambit


Darian Miller

unread,
Jul 24, 2004, 10:42:33 AM7/24/04
to
It's a fairly quick mod to get Indy 9 to work with attachments as streams.
As slightly altered from a newsgroup message awhile back:

IdMessage:
Type
TAttachmentType = (atFile, atStream); //new


TIdAttachment = class(TIdMessagePart)
protected
...
FAttachmentType:TAttachmentType;//new
FStream:TStream;//new
public
...
property AttachmentType: TAttachmentType read FAttachmentType write
FAttachmentType;//new
property Stream: TStream read FStream write FStream;//new
end;


procedure TIdAttachment.Assign(Source: TPersistent);
...
AttachmentType := mp.AttachmentType;//new
Stream := mp.Stream;//new
end;
end;

procedure TIdAttachment.Encode(ADest: TStream);
begin
with
TIdMessageEncoderInfo(TIdMessageParts(Collection).MessageEncoderInfo).Messag
eEncoderClass
.Create(nil) do try
Filename := Self.Filename;
if AttachmentType = atFile then//new
begin//new
Encode(Self.StoredPathname, ADest); //old
end//new
else//new
begin//new
Encode(Stream, ADest);//new
end;//new
finally Free; end;
end;

To use:
MyAttach := TIdAttachment.Create(MyMsg.MessageParts, cFileName);
MyAttach.AttachmentType := atStream;
MyAttach.Stream := MyStream;
MyAttach.ContentType := 'text/plain';

"Carlos Guerra" <cgu...@aduasys.com> wrote in message
news:4101b547$1...@newsgroups.borland.com...

Carlos Guerra

unread,
Jul 25, 2004, 1:46:15 PM7/25/04
to
Thank you very much, I'll give it a try both Indy 10 and the Darian
suggestion.

Regards

"Carlos Guerra" <cgu...@aduasys.com> wrote in message
news:4101b547$1...@newsgroups.borland.com...

0 new messages