🚀 go-pugleaf

RetroBBS NetNews Server

Inspired by RockSolid Light RIP Retro Guy

Thread View: borland.public.cppbuilder.internet.socket
6 messages
6 total messages Started by Antonio Donato Fri, 30 Jul 2004 18:21
Deleting Sent Attachments in Indy SMTP
#5533
Author: Antonio Donato
Date: Fri, 30 Jul 2004 18:21
10 lines
1131 bytes
I have an application that uses Indy SMTP to send mails. To attach a
mail I am using this code:

TIdAttachment *attachment1 = new
TIdAttachment(IndyMessage->MessageParts, AttachFileOne);

What code I have to use in order that, after having sent a mail message,
to delete the attachments? Thanks

Antonio Donato
Re: Deleting Sent Attachments in Indy SMTP
#5534
Author: Remy Lebeau (TeamB)
Date: Fri, 30 Jul 2004 18:37
16 lines
1293 bytes
"Antonio Donato" <espvida@osite.com.br> wrote in message
news:410A91BD.B2B07735@osite.com.br...

> What code I have to use in order that, after having
> sent a mail message, to delete the attachments? Thanks

Simply delete the TIdAttachment that you allocated:

    TIdAttachment *attachment1 = new
TIdAttachment(IndyMessage->MessageParts, AttachFileOne);
    //...
    delete attachment1;


Gambit
Re: Deleting Sent Attachments in Indy SMTP
#5535
Author: Antonio Donato
Date: Fri, 30 Jul 2004 19:22
26 lines
1590 bytes
I tried to do that, but BC++ gives strange responses.

When writing

delete attachment1;

compiling says "Undefined symbol attachment1", when it should not be
undefined.


"Remy Lebeau (TeamB)" ha escrito:

> "Antonio Donato" <espvida@osite.com.br> wrote in message
> news:410A91BD.B2B07735@osite.com.br...
>
> > What code I have to use in order that, after having
> > sent a mail message, to delete the attachments? Thanks
>
> Simply delete the TIdAttachment that you allocated:
>
>     TIdAttachment *attachment1 = new
> TIdAttachment(IndyMessage->MessageParts, AttachFileOne);
>     //...
>     delete attachment1;
>
> Gambit
Re: Deleting Sent Attachments in Indy SMTP
#5536
Author: Remy Lebeau (TeamB)
Date: Fri, 30 Jul 2004 21:06
16 lines
1312 bytes
"Antonio Donato" <espvida@osite.com.br> wrote in message
news:410AA00A.2810F892@osite.com.br...

> When writing
>
> delete attachment1;
>
> compiling says "Undefined symbol attachment1", when
> it should not be undefined.

Please show your actual code.  My guess would be that you are trying to
delete something that is no longer in scope.


Gambit
Re: Deleting Sent Attachments in Indy SMTP
#5537
Author: Antonio Donato
Date: Sun, 01 Aug 2004 17:01
112 lines
3511 bytes
Dear Remy,

actual code is this:


> int c;
> char textlabel[600];
> char TmpFileAddress[600];
> char ToMailTag[600], SubjectMailTag[2000];
> char CCMailTag[20000];
>
>
> strcpy(ToMailTag, ToEdit->Text.c_str());
>
> IndyMessage->Recipients->EMailAddresses=AnsiString(ToMailTag);
>
> strcpy(CCMailTag, CCEdit->Text.c_str());
>
> IndyMessage->CCList->EMailAddresses=AnsiString(CCMailTag);
>
> strcpy(SubjectMailTag, SubjectEdit->Text.c_str());
>
> IndyMessage->Subject=AnsiString(SubjectMailTag);
>
> if(AttachFileOne[0]!=0)
> TIdAttachment *attachment1 = new TIdAttachment(IndyMessage->MessageParts, AttachFileOne);
>
> outfp=fopen(TmpFileAddress, "w");
> fclose(outfp);
>
> RichEdit->PlainText=true;
> RichEdit->Lines->SaveToFile(AnsiString(TmpFileAddress));
> IndyMessage->Body->LoadFromFile(AnsiString(TmpFileAddress));
>
> try
> {
> IndySMTP->Connect(-1);
> }
>
> catch(...)
> {
> sprintf(textlabel, "Impossible connecting");
> OKDialog->DialogLabel->Caption = AnsiString(textlabel);
> OKDialog->Caption = "Message Box";
> OKDialog->ShowModal();
>
> IndySMTP->Disconnect();
>
> return;
> }
>
> try
> {
> IndySMTP->Send(IndyMessage);
> }
>
> catch(...)
> {
> sprintf(textlabel, "Impossible mailing");
> OKDialog->DialogLabel->Caption = AnsiString(textlabel);
> OKDialog->Caption = "Message Box";
> OKDialog->ShowModal();
>
> IndySMTP->Disconnect();
>
> //Note: with or without line "if(attachment1!=NULL)"
> //code does not compile and BC++ message is:
> //"Undefined symbol attachment1"
>
>
> if(attachment1!=NULL)
> delete attachment1;
>
> return;
> }
>
> IndySMTP->Disconnect();
>
> //Note: with or without line "if(attachment1!=NULL)"
> //code does not compile and BC++ message is:
> //"Undefined symbol attachment1"
>
> if(attachment1!=NULL)
> delete attachment1;
>
> sprintf(textlabel, "Successful sending");
> OKDialog->DialogLabel->Caption = AnsiString(textlabel);
> OKDialog->Caption = "Message Box";
> OKDialog->ShowModal();
>
>

I thank you very much all your attention.

Antonio

"Remy Lebeau (TeamB)" ha escrito:

> "Antonio Donato" <espvida@osite.com.br> wrote in message
> news:410AA00A.2810F892@osite.com.br...
>
> > When writing
> >
> > delete attachment1;
> >
> > compiling says "Undefined symbol attachment1", when
> > it should not be undefined.
>
> Please show your actual code.  My guess would be that you are trying to
> delete something that is no longer in scope.
>
> Gambit
Re: Deleting Sent Attachments in Indy SMTP
#5538
Author: Remy Lebeau (TeamB)
Date: Sun, 01 Aug 2004 20:49
33 lines
2029 bytes
"Antonio Donato" <espvida@osite.com.br> wrote in message
news:410D21DA.B5B85B81@osite.com.br...

> > if(AttachFileOne[0]!=0)
> > TIdAttachment *attachment1 = new
TIdAttachment(IndyMessage->MessageParts, AttachFileOne);

The pointer is indeed going out of scope.  That code is the same as this:

    if( AttachFileOne[0] != 0 )
    {
        TIdAttachment *attachment1 = new
TIdAttachment(IndyMessage->MessageParts, AttachFileOne);
    }

You can't access the pointer from outside the if() block because it only
exists inside the if() block.  You need to declare it outside the if()
block:

    TIdAttachment *attachment1 = NULL;
    if( AttachFileOne[0] != 0 )
        attachment1 = new TIdAttachment(IndyMessage->MessageParts,
AttachFileOne);

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

You could use SaveToStream() and LoadFromStream() instead, then you don't
need the temporary file anymore.


Gambit
Thread Navigation

This is a paginated view of messages in the thread with full content displayed inline.

Messages are displayed in chronological order, with the original post highlighted in green.

Use pagination controls to navigate through all messages in large threads.

Back to All Threads