Article View: borland.public.cppbuilder.internet.socket
Article #1959Re: TIdAttachment Problem with MIME Encoding
From: Remy Lebeau (TeamB)
Date: Wed, 20 Sep 2006 16:42
Date: Wed, 20 Sep 2006 16:42
80 lines
3774 bytes
3774 bytes
"Robert Lieblich" <nospam@nospam.com> wrote in message
news:45112258$1@newsgroups.borland.com...
> If IdMessage1->Encoding is set to: meMIME, the received attachment
> has got 16 bytes appended, with meUU (UUencoding), everything is ok.
What EXACTLY is being appended? Please be more specific. What does the
actual message data look like?
> I tried to free some memory at the end with attach1->Free();
> but then i get an Exception "EInvalidPointer" at this point. Why?
First and foremost, never call Free() directly. Use 'delete' instead.
Second, the TIdMessage owns the attachments, so you do not need to free them
manually. They will be freed automatically when the TIdMessage itself is
cleared or freed. Since you are clearing the TIdMessage before freeing the
TIdAttachment, your pointer to the attachment is invalid by the time you try
to free it. That is why you are getting the exception - the attachment has
already been freed by Indy itself.
> TIdAttachment *attach1 = new TIdAttachment(IdMessage1->MessageParts,
"c:\\attachment.txt" ) ;
Because you are using the MessageParts collection, you should be storing the
message text into the collection as well, not in the TIdMessage::Body.
> attach1->ContentType= "multipart/mixed";
That is the completely wrong ContentType to use. You are attaching a text
file, so you have to use "text/plain" instead. You are not creating your
own multipart containers, so you should not be using the "multipart" type at
all, except at the top level of the TIdMessage.
Try this code instead:
void __fastcall TForm1::Button1Click(TObject *Sender)
{
IdMessage1->Clear();
IdMessage1->Encoding = meMIME;
TIdText *text1 = new TIdText(IdMessage1->MessageParts, NULL);
text1->Body->Add("Some text...");
text1->ContentType = "text/plain";
TIdAttachment *attach1 = new TIdAttachment(IdMessage1->MessageParts,
"c:\\attachment.txt");
attach1->ContentType = "text/plain";
IdMessage1->From->Name = "SENDERNAME";
IdMessage1->From->Address = "SENDERADDRESS";
IdMessage1->Subject = "Test BDS2006/Indy9 19.9.06" ;
IdMessage1->Recipients->EMailAddresses = Edit2->Text;
IdMessage1->ContentType = "multipart/mixed";
IdSMTP1->Host = Edit7->Text;
if( CheckBox1->Checked )
{
IdSMTP1->Username = Edit4->Text;
IdSMTP1->Password = Edit5->Text;
IdSMTP1->AuthenticationType = atLogin;
}
else
IdSMTP1->AuthenticationType = atNone;
IdSMTP1->Connect(4000);
try
{
IdSMTP1->Send(IdMessage1);
}
__finally {
IdSMTP1->Disconnect();
}
IdMessage1->Clear();
}
Gambit
Technical Details
Message-ID:
<45117004$1@newsgroups.borland.com>Path:
arc1-ca.pugleaf.net!g2news2.google.com!news1.google.com!news3.google.com!border1.nntp.dca.giganews.com!nntp.giganews.com!newsfeed00.sul.t-online.de!newsfeed01.sul.t-online.de!t-online.de!newsgroups.borland.com!not-for-mailReferences:
<45112258$1@newsgroups.borland.com>Show Full Headers
Complete Article Headers
X-Google-Thread: 11508e,edd2a3551c00f96a X-Google-Attributes: gid11508e,public X-Google-Language: ENGLISH,ASCII-7-bit From: "Remy Lebeau \(TeamB\)" <no.spam@no.spam.com> Newsgroups: borland.public.cppbuilder.internet.socket References: <45112258$1@newsgroups.borland.com> Subject: Re: TIdAttachment Problem with MIME Encoding Date: Wed, 20 Sep 2006 09:42:27 -0700 Lines: 82 X-Priority: 3 X-MSMail-Priority: Normal X-Newsreader: Microsoft Outlook Express 6.00.2800.1409 X-MimeOLE: Produced By Microsoft MimeOLE V6.00.2800.1409 NNTP-Posting-Host: 69.169.4.232 Message-ID: <45117004$1@newsgroups.borland.com> X-Trace: newsgroups.borland.com 1158770692 69.169.4.232 (20 Sep 2006 09:44:52 -0700) Path: arc1-ca.pugleaf.net!g2news2.google.com!news1.google.com!news3.google.com!border1.nntp.dca.giganews.com!nntp.giganews.com!newsfeed00.sul.t-online.de!newsfeed01.sul.t-online.de!t-online.de!newsgroups.borland.com!not-for-mail