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

Attachments with TIdMessage

144 views
Skip to first unread message

Antonio Donato

unread,
Jun 26, 2004, 3:35:24 PM6/26/04
to
I am trying to send an attachment in an application thar has a TIdSMTP
and a TIdMessage by Borland C++5. In the properties of Message there are
Body, Subject, CCList and others, but no Attachment property. The book
Indy in Depth does not tell about attachments. Hwever, to send an
attachment must be a very simple thing. Can someone explain me how to do
it? I also found two articles in Dephi about it, but unhappily I do not
understand Delphy, only CB++. Thank all you.

Antonio Donato

Remy Lebeau (TeamB)

unread,
Jun 26, 2004, 7:04:58 PM6/26/04
to

"Antonio Donato" <esp...@osite.com.br> wrote in message
news:40DDCFFC...@osite.com.br...

> In the properties of Message there are Body, Subject,
> CCList and others, but no Attachment property.

You need to add a TIdAttachment instance to the MessageParts collection, ie:

TIdAttachment *attachment = new TIdAttachment(IdMessage1, "c:\\path
to\\file.ext");
attachment->FileName = "file.ext";
attachment->ContentType = "whatever";
// etc...


Gambit


Antonio Donato

unread,
Jun 26, 2004, 11:48:13 PM6/26/04
to
> Dear Remy,
>
> I compiled that code below and the result was:
>
>
> Could not find a match for 'TIdAttachment::TIdAttachment(TIdMessage *, char")'
>
>
> If you know what is this I thank you very much. Thanks.
>
> Antonio Donato
>
"Remy Lebeau (TeamB)" ha escrito:

Remy Lebeau (TeamB)

unread,
Jun 27, 2004, 12:55:40 AM6/27/04
to

"Antonio Donato" <esp...@osite.com.br> wrote in message
news:40DE437D...@osite.com.br...

> I compiled that code below and the result was:
>
>
> Could not find a match for 'TIdAttachment::TIdAttachment(TIdMessage *,
char")'

Please show your actual code.


Gambit


Antonio Donato

unread,
Jun 27, 2004, 7:32:44 PM6/27/04
to
Dear Remy Lebeau,

the code is the following. Note that I did not found at Compenent Palette at
BC++5 in which I installed Indy any icon to TIdAttachment, but there are in it
Icons for TIdMessage and TIdSMTP, which I put in application form. Absence of
TIdAttachment in Component Palette in BC++ is something correct or wrong?

I thank you very much for all your and any other's attention.

Antonio Donato

> IndyMessage->From->Name=AnsiString(NameMailTag);
> IndyMessage->From->Address=AnsiString(ReturnMailTag);
> IndyMessage->Recipients->EMailAddresses=AnsiString(ToMailTag);
> IndyMessage->CCList->EMailAddresses=AnsiString(CCMailTag);
> IndyMessage->BccList->EMailAddresses=AnsiString(CCOMailTag);
> IndyMessage->Subject=AnsiString(SubjectMailTag);
>
> IndySMTP->Host=AnsiString(SMTPMailTag);
> IndySMTP->Username=AnsiString(LoginMailTag);
> IndySMTP->Password=AnsiString(PasswordMailTag);
> IndySMTP->AuthenticationType=atLogin;
>
>
> strcpy(AttachTag, MailForm->AttachEdit->Text.c_str());
>
> outfp=fopen(TmpFileAddress, "w");
> fclose(outfp);
>
> RichEdit->PlainText=true;
> RichEdit->Lines->SaveToFile(AnsiString(TmpFileAddress));
> IndyMessage->Body->LoadFromFile(AnsiString(TmpFileAddress));
>
> if(AttachTag[0]!=0)
> {
> TIdAttachment *attachment = new TIdAttachment(IndyMessage, AttachTag);
> attachment->FileName = "file.zip";
> }
>
>
> TCursor oldCursor = Screen->Cursor;
> Screen->Cursor = crHourGlass;
> Application->ProcessMessages();
>
>
> try
> {
> IndySMTP->Connect(-1);
> }
>
> catch(...)
> {
> sprintf(textlabel, "Impossible to connect.");
> OKDialog->DialogLabel->Caption = AnsiString(textlabel);
> OKDialog->Caption = "Message Box";
> OKDialog->ShowModal();
>
> IndySMTP->Disconnect();
> Screen->Cursor = oldCursor;
> Close();
> return;
> }
>
>
> try
> {
> IndySMTP->Send(IndyMessage);
> }
>
> catch(...)
> {
> sprintf(textlabel, "Impossible to send");
> OKDialog->DialogLabel->Caption = AnsiString(textlabel);
> OKDialog->Caption = "Message Box";
> OKDialog->ShowModal();
>
> IndySMTP->Disconnect();
> Screen->Cursor = oldCursor;
> return;
> }
>
> IndySMTP->Disconnect();
>
> Screen->Cursor = oldCursor;
>
>

"Remy Lebeau (TeamB)" ha escrito:

> "Antonio Donato" <esp...@osite.com.br> wrote in message

Remy Lebeau (TeamB)

unread,
Jun 27, 2004, 9:21:31 PM6/27/04
to

"Antonio Donato" <esp...@osite.com.br> wrote in message
news:40DF591C...@osite.com.br...

> the code is the following.

> Note that I did not found at Compenent Palette at
> BC++5 in which I installed Indy any icon to
> TIdAttachment

TIdAttachment is not a component to begin with, thus it does not appear in
the Component Palette.

> but there are in it Icons for TIdMessage and TIdSMTP

Those, on the other hand, ae actual components, thus they appear in the
Palette.

> Absence of TIdAttachment in Component Palette in
> BC++ is something correct or wrong?

TIdAttachment is not a component, thus you have to instantiate in code, not
visually at design-time. I already gave you the code to do that.

> > RichEdit->PlainText=true;
> > RichEdit->Lines->SaveToFile(AnsiString(TmpFileAddress));
> > IndyMessage->Body->LoadFromFile(AnsiString(TmpFileAddress));

You could do the following instead, then you don't need the temporary file
anymore:

IndyMessage->Body->Assign(RichEdit->Lines);

> > TIdAttachment *attachment = new TIdAttachment(IndyMessage, AttachTag);

That should be this instead:

TIdAttachment *attachment = new TIdAttachment(IndyMessage->MessageParts,
AttachTag);


Gambit


Antonio Donato

unread,
Jun 28, 2004, 1:12:42 AM6/28/04
to
Dear Remy,

thank you very much, it was done! Let me ask a further question, if we must send
more than one attached in a same e-mail, is it possible with TIdAttachment, and
what would be the code?

Antonio Donato

"Remy Lebeau (TeamB)" ha escrito:

> "Antonio Donato" <esp...@osite.com.br> wrote in message

Remy Lebeau (TeamB)

unread,
Jun 28, 2004, 1:22:04 AM6/28/04
to

"Antonio Donato" <esp...@osite.com.br> wrote in message
news:40DFA8C...@osite.com.br...

> if we must send more than one attached in a same e-mail,
> is it possible with TIdAttachment

Yes. You simply create more TIdAttachment instances.

> and what would be the code?

You already have that code.


Gambit


Antonio Donato

unread,
Jun 28, 2004, 1:36:05 PM6/28/04
to
Dear Remy,

It's all OK, all was perfectly done. I have to thank you for your help
and for your readness in doing so.

Antonio Donato

"Remy Lebeau (TeamB)" ha escrito:

> "Antonio Donato" <esp...@osite.com.br> wrote in message

0 new messages