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

Sending E-Mail with Attachment using TIdMessage

2,243 views
Skip to first unread message

Otto Herdegen

unread,
Jul 24, 2008, 6:21:12 AM7/24/08
to
Hi NG,

i have looked at www.indiproject.org www.atozed.com and www.deja.com but i
did not find a *working* example how to use TIdMessage with a Attachment in
Delphi 2007. All examples i have found work only with older Delphi versions,
or without Attachment. After playing with this problem some days, this makes
me crazy.

I have assigned TIdMessage.OnCreateAttachment . . .

procedure TMailerForm.MailMessageCreateAttachment(const AMsg: TIdMessage;
const AHeaders: TStrings; var AAttachment: TIdAttachment);

.... and here AAttachment is "nil", so a assume it must be created and
filled in with data here. But anything i do, always exception.

Can you please give me a hint in the right direction?

Thank you very much

Kind Regards
Otto

Remy Lebeau (TeamB)

unread,
Jul 24, 2008, 2:09:17 PM7/24/08
to

"Otto Herdegen" <otto.h...@rubin-soft.de> wrote in message
news:4888...@newsgroups.borland.com...

> i have looked at www.indiproject.org www.atozed.com and www.deja.com
> but i did not find a *working* example how to use TIdMessage with
> a Attachment in Delphi 2007.

There have been numerous examples posted before that should be in the Deja
archives.

> I have assigned TIdMessage.OnCreateAttachment . . .

That only applies when RECEIVING/LOADING emails, not when SENDING emails.

> procedure TMailerForm.MailMessageCreateAttachment(const AMsg: TIdMessage;
> const AHeaders: TStrings; var AAttachment: TIdAttachment);
>
> .... and here AAttachment is "nil"

As it should be. The purpose of OnCreateAttachment is to allow you to tell
TIdMessage which TIdAttachment descendant class to use when parsing received
email data. If OnCreateAttachment is not assigned, or returns nil, then
TIdMessage uses TIdAttachmentFile. If you don't want to use temporary files
then you can set AAttachment to an instance of a more suitable TIdAttachment
descendant class, such as TIdAttachmentMemory.

> Can you please give me a hint in the right direction?

For SENDING emails, simply create instances of the desired TIdAttachment
descendant class(es) and set the TIdMessage.MessageParts collection as the
Owner, ie:

...
Attachment := TIdAttachmentFile.Create(IdMessage1.MessageParts, 'c:\some
file.ext');
// set attachment properties as needed...
...
SMTP.Send(IdMessage1);


Gambit


Otto Herdegen

unread,
Jul 25, 2008, 4:37:37 AM7/25/08
to
Hi Gambit,

> Attachment := TIdAttachmentFile.Create(IdMessage1.MessageParts,
> 'c:\some file.ext');

oh yeahhh... that single line did it. Thank you very much for that!

Kind Regards
Otto

0 new messages