BorlandTalk.com Forum Index BorlandTalk.com
Borland discussion newsgroups
 
Archives   FAQFAQ   SearchSearch   MemberlistMemberlist   UsergroupsUsergroups   RegisterRegister 
 ProfileProfile   Log in to check your private messagesLog in to check your private messages   Log inLog in 

How to send an attachment to an e-mail
Goto page 1, 2  Next
 
Post new topic   Reply to topic    BorlandTalk.com Forum Index -> C++ Builder (Internet Socket)
View previous topic :: View next topic  
Author Message
David Ayre
Guest





PostPosted: Tue Aug 15, 2006 10:34 pm    Post subject: How to send an attachment to an e-mail Reply with quote



Hi,
I am using TIdSMTP from Indy 9 with BDS2006 and have mastered the
sending of a standard e-mail, but would like to know how to send
an attachment.

Thanks,

David
Back to top
Remy Lebeau (TeamB)
Guest





PostPosted: Tue Aug 15, 2006 11:33 pm    Post subject: Re: How to send an attachment to an e-mail Reply with quote



"David Ayre" <davidcayre (AT) ntlworld (DOT) com> wrote in message
news:44e2059a$1 (AT) newsgroups (DOT) borland.com...

Quote:
I am using TIdSMTP from Indy 9 with BDS2006 and have mastered
the sending of a standard e-mail, but would like to know how to send
an attachment.

Add a TIdAttachment object to the TIdMessage.MessageParts collection. You
will also have to add TIdText objects for your text as well, instead of
using the TIdMessage.Body property.


Gambit
Back to top
David Ayre
Guest





PostPosted: Tue Aug 15, 2006 11:50 pm    Post subject: Re: How to send an attachment to an e-mail Reply with quote



"Remy Lebeau \(TeamB\)" <no.spam (AT) no (DOT) spam.com> wrote:
Quote:

"David Ayre" <davidcayre (AT) ntlworld (DOT) com> wrote in message
news:44e2059a$1 (AT) newsgroups (DOT) borland.com...

I am using TIdSMTP from Indy 9 with BDS2006 and have mastered
the sending of a standard e-mail, but would like to know how to send
an attachment.

Add a TIdAttachment object to the TIdMessage.MessageParts collection. You
will also have to add TIdText objects for your text as well, instead of
using the TIdMessage.Body property.


Gambit


Thanks Remy,


But how do I do that? There doesn't seem to be a TIdAttachment
component in the Indy list.

Cheers,

David
Back to top
Remy Lebeau (TeamB)
Guest





PostPosted: Wed Aug 16, 2006 6:40 am    Post subject: Re: How to send an attachment to an e-mail Reply with quote

"David Ayre" <davidcayre (AT) ntlworld (DOT) com> wrote in message
news:44e2178f$1 (AT) newsgroups (DOT) borland.com...

Quote:
But how do I do that? There doesn't seem to be a
TIdAttachment component in the Indy list.

TIdText and TIdAttachment are not components. They are TCollectionItem
descendants. You have to instantiate them programmably in code, ie:

TIdText *text = new TIdText(IdMessage1->MessageParts, NULL);
text->ContentType = "text/plain";
text->Body->Text = "whatever";

TIdText *html = new TIdText(IdMessage1->MessageParts, NULL);
html->ContentType = "text/html";
html->Body->Text = "<html>whatever</html>";

TIdAttachment *attach = new TIdAttachment(IdMessage1->MessageParts,
"c:\\some file.ext");
attach->ContentType = GetMimeTypeFromFile(attach->FileName);


Gambit
Back to top
David Ayre
Guest





PostPosted: Wed Aug 16, 2006 1:19 pm    Post subject: Re: How to send an attachment to an e-mail Reply with quote

Quote:
TIdText *text = new TIdText(IdMessage1->MessageParts, NULL);

TIdAttachment *attach = new TIdAttachment(IdMessage1->MessageParts,
"c:\\some file.ext");


Thanks Remy,

That makes it all clear.
I assume that text and attach must be deteted at the end?

Cheers,

David
Back to top
David Ayre
Guest





PostPosted: Wed Aug 16, 2006 1:41 pm    Post subject: Re: How to send an attachment to an e-mail Reply with quote

Quote:
attach->ContentType = GetMimeTypeFromFile(attach->FileName);


This line won't compile - GetMimeTypeFromFile() must need an
#include. The Indy help says that it is in global.pas. Do I need
to include global.pas in my project or just add an include for
its header file?

Cheers,

David
Back to top
Remy Lebeau (TeamB)
Guest





PostPosted: Wed Aug 16, 2006 9:52 pm    Post subject: Re: How to send an attachment to an e-mail Reply with quote

"David Ayre" <davidcayre (AT) ntlworld (DOT) com> wrote in message
news:44e2d502$1 (AT) newsgroups (DOT) borland.com...

Quote:
I assume that text and attach must be deteted at the end?

No. They are owned by the TIdMessage. They will be free automatically when
the TIdMessage itself is freed, or when you call TIdMessage.Clear/Body().


Gambit
Back to top
Remy Lebeau (TeamB)
Guest





PostPosted: Wed Aug 16, 2006 9:55 pm    Post subject: Re: How to send an attachment to an e-mail Reply with quote

"David Ayre" <davidcayre (AT) ntlworld (DOT) com> wrote in message
news:44e2da4d$1 (AT) newsgroups (DOT) borland.com...

Quote:
This line won't compile - GetMimeTypeFromFile() must need
an #include.

GetMimeTypeFromFile() is declared in the IdGlobal unit, which is already
included by TIdSMTP's unit.

Quote:
The Indy help says that it is in global.pas. Do I need to include
global.pas in my project

No.

Quote:
or just add an include for its header file?

Just the header file - IdGlobal.hpp, which IdSMTP.hpp already includes. So
you should not have had a compiler error saying the function is unknown,
because it is a known function.


Gambit
Back to top
Roger
Guest





PostPosted: Wed Aug 16, 2006 10:03 pm    Post subject: Re: How to send an attachment to an e-mail Reply with quote

Did you try:

include "IDGLOBAL.hpp"



"David Ayre" <davidcayre (AT) ntlworld (DOT) com> wrote in message
news:44e2da4d$1 (AT) newsgroups (DOT) borland.com...
Quote:


attach->ContentType = GetMimeTypeFromFile(attach->FileName);


This line won't compile - GetMimeTypeFromFile() must need an
#include. The Indy help says that it is in global.pas. Do I need
to include global.pas in my project or just add an include for
its header file?

Cheers,

David
Back to top
David Ayre
Guest





PostPosted: Thu Aug 17, 2006 2:15 pm    Post subject: Re: How to send an attachment to an e-mail Reply with quote

I've included IdGlobal.hpp. IdSMTP.hpp was already included,
but it still says that GetMimeTypeFromFile() is not declared.
I have got attach->Filename in the brackets.

Cheers,

David


"Remy Lebeau \(TeamB\)" <no.spam (AT) no (DOT) spam.com> wrote:
Quote:

"David Ayre" <davidcayre (AT) ntlworld (DOT) com> wrote in message
news:44e2da4d$1 (AT) newsgroups (DOT) borland.com...

This line won't compile - GetMimeTypeFromFile() must need
an #include.

GetMimeTypeFromFile() is declared in the IdGlobal unit, which is already
included by TIdSMTP's unit.

The Indy help says that it is in global.pas. Do I need to include
global.pas in my project

No.

or just add an include for its header file?

Just the header file - IdGlobal.hpp, which IdSMTP.hpp already includes. So
you should not have had a compiler error saying the function is unknown,
because it is a known function.


Gambit

Back to top
David Ayre
Guest





PostPosted: Thu Aug 17, 2006 8:40 pm    Post subject: Re: How to send an attachment to an e-mail Reply with quote

Yes Roger,

Tried that and if I type in:-

GetMimeTypeFromFile( I get a popup saying that there is no
prototype for this. That's what usually happens when I have
forgotten to include a header file.

I have found that if I use the line :-

attach->ContentType = "binary"; it works OK except that the
text->Body->Text = acBody; doesn't put the body text in. I
have to put it in the IdMessage->Body instead and then it
works.

Cheers,

David


"Roger" <aretae (AT) magma (DOT) ca> wrote:
Quote:
Did you try:

include "IDGLOBAL.hpp"



"David Ayre" <davidcayre (AT) ntlworld (DOT) com> wrote in message
news:44e2da4d$1 (AT) newsgroups (DOT) borland.com...


attach->ContentType = GetMimeTypeFromFile(attach->FileName);


This line won't compile - GetMimeTypeFromFile() must need an
#include. The Indy help says that it is in global.pas. Do I need
to include global.pas in my project or just add an include for
its header file?

Cheers,

David


Back to top
Remy Lebeau (TeamB)
Guest





PostPosted: Thu Aug 17, 2006 9:38 pm    Post subject: Re: How to send an attachment to an e-mail Reply with quote

"David Ayre" <davidcayre (AT) ntlworld (DOT) com> wrote in message
news:44e433c8 (AT) newsgroups (DOT) borland.com...

Quote:
I've included IdGlobal.hpp. IdSMTP.hpp was already included,
but it still says that GetMimeTypeFromFile() is not declared.

Double-check the case of the letters:

extern PACKAGE AnsiString __fastcall GetMIMETypeFromFile(const
AnsiString AFile);


Gambit
Back to top
Remy Lebeau (TeamB)
Guest





PostPosted: Thu Aug 17, 2006 9:40 pm    Post subject: Re: How to send an attachment to an e-mail Reply with quote

"David Ayre" <davidcayre (AT) ntlworld (DOT) com> wrote in message
news:44e48ddd$1 (AT) newsgroups (DOT) borland.com...

Quote:
attach->ContentType = "binary"; it works OK

That is not a proper ContentType value.

Quote:
except that the
text->Body->Text = acBody;
doesn't put the body text in.

Then you did not use it correctly. Please show the actual code you are
using, and the raw data that TIdMessage generates.

Quote:
I have to put it in the IdMessage->Body instead and then it works.

Do not mix TIdMessage::Body with TIdMessage.MessageParts. Use one or the
other, not both.


Gambit
Back to top
David Ayre
Guest





PostPosted: Thu Aug 17, 2006 10:25 pm    Post subject: Re: How to send an attachment to an e-mail Reply with quote

"Remy Lebeau \(TeamB\)" <no.spam (AT) no (DOT) spam.com> wrote:
Quote:

"David Ayre" <davidcayre (AT) ntlworld (DOT) com> wrote in message
news:44e48ddd$1 (AT) newsgroups (DOT) borland.com...

attach->ContentType = "binary"; it works OK

That is not a proper ContentType value.

except that the
text->Body->Text = acBody;
doesn't put the body text in.

Then you did not use it correctly. Please show the actual code you are
using, and the raw data that TIdMessage generates.

I have to put it in the IdMessage->Body instead and then it works.

Do not mix TIdMessage::Body with TIdMessage.MessageParts. Use one or the
other, not both.


Gambit

Hi Remy,


This is the full code for this section:-
//Send Email
IdSMTP1->Host = Edit1->Text;
IdSMTP1->Port = 25;
IdMessage1->From->Address = Edit2->Text;
IdMessage1->Recipients->EMailAddresses = Edit3->Text;
IdMessage1->Subject = acHeader;
//IdMessage1->Body->Text = acBody;
IdMessage1->From->Name = Edit4->Text;

TIdText *Text = new TIdText(IdMessage1->MessageParts,NULL);
Text->ContentType = "text/plain";
Text->Body->Text = acBody;

TIdAttachment *Attach = new TIdAttachment(IdMessage1->MessageParts,acAttachment);
Attach->ContentType = GetMIMETypeFromFile(Attach->FileName);

IdSMTP1->Connect(1000);
IdSMTP1->Send(IdMessage1);

if(IdSMTP1->Connected())IdSMTP1->Disconnect();

The GetMIMETypeFromFile(Attach->FileName); works now I've got
the MIME part in uppercase.
If I use the Text->Body->Text = acBody; as above, no body
text appears in the body of the e-mail. But if I use the
IdMessage1->Body->Text = acBody; it does.
acBody, acHeader and acAttachment are char * and contain the correct strings.

Cheers,

David
Back to top
Remy Lebeau (TeamB)
Guest





PostPosted: Fri Aug 18, 2006 12:40 am    Post subject: Re: How to send an attachment to an e-mail Reply with quote

"David Ayre" <davidcayre (AT) ntlworld (DOT) com> wrote in message
news:44e4a6a5$1 (AT) newsgroups (DOT) borland.com...

Quote:
IdSMTP1->Connect(1000);
IdSMTP1->Send(IdMessage1);

if(IdSMTP1->Connected())IdSMTP1->Disconnect();

Wrap that in a try..finally block instead:

IdSMTP1->Connect(1000);
try {
IdSMTP1->Send(IdMessage1);
}
__finally {
IdSMTP1->Disconnect();
}

Quote:
If I use the Text->Body->Text = acBody; as above, no
body text appears in the body of the e-mail.

You did not set the TIdMessage::ContentType property so that the receiver
would know the formatting of the message:

IdMessage1->ContentType = "multipart/mixed";

Also, older versions of Indy require a minimum of *2* TIdText parts - one
for plain text and one for html.


Gambit
Back to top
Display posts from previous:   
Post new topic   Reply to topic    BorlandTalk.com Forum Index -> C++ Builder (Internet Socket) All times are GMT
Goto page 1, 2  Next
Page 1 of 2

 
Jump to:  
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum


Powered by phpBB © 2001, 2006 phpBB Group
SEO toolkit © 2004-2006 webmedic.