🚀 go-pugleaf

RetroBBS NetNews Server

Inspired by RockSolid Light RIP Retro Guy

Thread View: borland.public.cppbuilder.internet.socket
16 messages
16 total messages Started by David Ayre Tue, 15 Aug 2006 17:34
How to send an attachment to an e-mail
#2100
Author: David Ayre
Date: Tue, 15 Aug 2006 17:34
9 lines
1042 bytes
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
Re: How to send an attachment to an e-mail
#2101
Author: Remy Lebeau (TeamB)
Date: Tue, 15 Aug 2006 18:33
14 lines
1357 bytes
"David Ayre" <davidcayre@ntlworld.com> wrote in message
news:44e2059a$1@newsgroups.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
Re: How to send an attachment to an e-mail
#2102
Author: David Ayre
Date: Tue, 15 Aug 2006 18:50
26 lines
1615 bytes
"Remy Lebeau \(TeamB\)" <no.spam@no.spam.com> wrote:
>
>"David Ayre" <davidcayre@ntlworld.com> wrote in message
>news:44e2059a$1@newsgroups.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
Re: How to send an attachment to an e-mail
#2103
Author: Remy Lebeau (TeamB)
Date: Wed, 16 Aug 2006 01:40
24 lines
1790 bytes
"David Ayre" <davidcayre@ntlworld.com> wrote in message
news:44e2178f$1@newsgroups.borland.com...

> 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
Re: How to send an attachment to an e-mail
#2104
Author: David Ayre
Date: Wed, 16 Aug 2006 08:19
16 lines
1301 bytes

>    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
Re: How to send an attachment to an e-mail
#2105
Author: David Ayre
Date: Wed, 16 Aug 2006 08:41
13 lines
1244 bytes

>    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
Re: How to send an attachment to an e-mail
#2107
Author: Remy Lebeau (TeamB)
Date: Wed, 16 Aug 2006 16:52
11 lines
1374 bytes
"David Ayre" <davidcayre@ntlworld.com> wrote in message
news:44e2d502$1@newsgroups.borland.com...

> 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
Re: How to send an attachment to an e-mail
#2108
Author: Remy Lebeau (TeamB)
Date: Wed, 16 Aug 2006 16:55
23 lines
1681 bytes
"David Ayre" <davidcayre@ntlworld.com> wrote in message
news:44e2da4d$1@newsgroups.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
Re: How to send an attachment to an e-mail
#2106
Author: Roger
Date: Wed, 16 Aug 2006 17:03
22 lines
1555 bytes
Did you try:

include "IDGLOBAL.hpp"



"David Ayre" <davidcayre@ntlworld.com> wrote in message 
news:44e2da4d$1@newsgroups.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
> 
Re: How to send an attachment to an e-mail
#2109
Author: David Ayre
Date: Thu, 17 Aug 2006 09:15
36 lines
2011 bytes
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@no.spam.com> wrote:
>
>"David Ayre" <davidcayre@ntlworld.com> wrote in message
>news:44e2da4d$1@newsgroups.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
>
>
Re: How to send an attachment to an e-mail
#2110
Author: David Ayre
Date: Thu, 17 Aug 2006 15:40
46 lines
2129 bytes
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@magma.ca> wrote:
>Did you try:
>
>include "IDGLOBAL.hpp"
>
>
>
>"David Ayre" <davidcayre@ntlworld.com> wrote in message 
>news:44e2da4d$1@newsgroups.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
>> 
>
>
Re: How to send an attachment to an e-mail
#2111
Author: Remy Lebeau (TeamB)
Date: Thu, 17 Aug 2006 16:38
14 lines
1419 bytes
"David Ayre" <davidcayre@ntlworld.com> wrote in message
news:44e433c8@newsgroups.borland.com...

> 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
Re: How to send an attachment to an e-mail
#2112
Author: Remy Lebeau (TeamB)
Date: Thu, 17 Aug 2006 16:40
22 lines
1629 bytes
"David Ayre" <davidcayre@ntlworld.com> wrote in message
news:44e48ddd$1@newsgroups.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
Re: How to send an attachment to an e-mail
#2113
Author: David Ayre
Date: Thu, 17 Aug 2006 17:25
59 lines
2900 bytes
"Remy Lebeau \(TeamB\)" <no.spam@no.spam.com> wrote:
>
>"David Ayre" <davidcayre@ntlworld.com> wrote in message
>news:44e48ddd$1@newsgroups.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
Re: How to send an attachment to an e-mail
#2114
Author: Remy Lebeau (TeamB)
Date: Thu, 17 Aug 2006 19:40
32 lines
2003 bytes
"David Ayre" <davidcayre@ntlworld.com> wrote in message
news:44e4a6a5$1@newsgroups.borland.com...

> 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();
    }

> 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
Re: How to send an attachment to an e-mail
#2115
Author: David Ayre
Date: Fri, 18 Aug 2006 08:27
52 lines
2482 bytes
Thanks Remy,

I think that explains everything now.

It may be me, but I find it difficult to get what I want from
the Indy help files. I'm sure all the info is there when you
know the answers, but it is very difficult to find out what
you have to do when you don't know how it works in the first
place.
I find your explanations very helpful and I thank you for that.

All the best,

David


"Remy Lebeau \(TeamB\)" <no.spam@no.spam.com> wrote:
>
>"David Ayre" <davidcayre@ntlworld.com> wrote in message
>news:44e4a6a5$1@newsgroups.borland.com...
>
>> 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();
>    }
>
>> 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
>
>
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