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
> 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
> 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