🚀 go-pugleaf

RetroBBS NetNews Server

Inspired by RockSolid Light RIP Retro Guy

Thread View: borland.public.cppbuilder.internet.socket
15 messages
15 total messages Started by Francesco Thu, 22 Dec 2005 14:17
Send Html Email with Indy component doesn't work
#2930
Author: Francesco
Date: Thu, 22 Dec 2005 14:17
80 lines
3007 bytes

Hi,

  I want to send a html mail using SMTP of Indy 9, when i receive the
mail i see the attaches but the mail is empty, This is my code, what's
wrong?

   Thanks in advance.



  MailMessage->From->Address = "mail@mail.com";
  MailMessage->From->Name = "sender";
  MailMessage->Recipients->EMailAddresses = "info@mail.com";
    
    TStringList *Temp = new TStringList();
    Temp->LoadFromFile("c:\\mail.htm");
    MailMessage->IsEncoded = true;
    MailMessage->ContentTransferEncoding = "7bit";
    MailMessage->ContentType = "multipart/mixed"; // I've tried with
multipart/related; type="text/html" but doesn't work too
    
    TIdText *body = new TIdText(MailMessage->MessageParts, Temp);
    body->ContentType = "text/html";
    
    delete Temp;  

    //---CARICO IMMAGINE
    TIdAttachment *IImagePart3 = new
TIdAttachment(MailMessage->MessageParts, "c:\\topaug.gif");
    IImagePart3->ContentType = "image/gif";
    IImagePart3->ExtraHeaders->Values["Content-ID"] = "topaug.gif";
    IImagePart3->FileName = "topaug.gif";

    TIdAttachment *IImagePart = new
TIdAttachment(MailMessage->MessageParts, "c:\\content.gif");
    IImagePart->ContentType = "image/gif";
    IImagePart->ExtraHeaders->Values["Content-ID"] = "content.gif";
    IImagePart->FileName = "content.gif";

    TIdAttachment *IImagePart2 = new
TIdAttachment(MailMessage->MessageParts, "c:\\down.gif");
    IImagePart2->ContentType = "image/gif";
    IImagePart2->ExtraHeaders->Values["Content-ID"] = "down.gif";
    IImagePart2->FileName = "down.gif";

    .....


this is mail.htm:

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN">

<html>
<head>
	<title>sample</title>
</head>

<body>


	<table width="" align="center" border="0" cellSpacing=0 cellPadding=0>
<tr>
	<td><img src="cid:topaug.gif" width="662" height="155" alt=""
border="0"></td>
</tr>
<tr>
	<td><img src="cid:content.gif" width="662" height="341" alt=""
border="0"></td>
</tr>
<tr>
	<td valign="top"><img src="cid:down.gif" width="662" height="133"
alt="" border="0"></td>
</tr>
</table>


</body>
</html>
Re: Send Html Email with Indy component doesn't work
#2931
Author: Remy Lebeau (TeamB)
Date: Thu, 22 Dec 2005 19:00
37 lines
2152 bytes
<Francesco> wrote in message news:43aac389@newsgroups.borland.com...

>   I want to send a html mail using SMTP of Indy 9, when
> i receive the mail i see the attaches but the mail is empty

Try this instead:

    MailMessage->From->Address = "mail@mail.com";
    MailMessage->From->Name = "sender";
    MailMessage->Recipients->EMailAddresses = "info@mail.com";
    MailMessage->ContentType = "multipart/related; type=\"text/html\"";

    TIdText *HTML = new TIdText(MainMessage->MessageParts, NULL);
    HTML->Body->LoadFromFile("c:\\mail.htm");
    HTML->ContentType = "text/html";

    TIdAttachment *IImagePart = new TIdAttachment(MailMessage->MessageParts,
"c:\\content.gif");
    IImagePart->ContentID = "content.gif";
    IImagePart->ContentType = "image/gif";
    IImagePart->FileName = "content.gif";

    TIdAttachment *IImagePart2 = new
TIdAttachment(MailMessage->MessageParts, "c:\\down.gif");
    IImagePart2->ContentID = "down.gif";
    IImagePart2->ContentType = "image/gif";
    IImagePart2->FileName = "down.gif";

    TIdAttachment *IImagePart3 = new
TIdAttachment(MailMessage->MessageParts, "c:\\topaug.gif");
    IImagePart3->ContentID = "topaug.gif";
    IImagePart3->ContentType = "image/gif";
    IImagePart3->FileName = "topaug.gif";


Gambit
Re: Send Html Email with Indy component doesn't work
#2932
Author: Francesco
Date: Fri, 23 Dec 2005 06:44
66 lines
2749 bytes

  Hi Remy,

  thank you for the advise but I've an error, 
  
  [C++ Error] Main.cpp(180): E2316 'ContentID' is not a member of
'TIdAttachment'
[C++ Error] Main.cpp(186): E2316 'ContentID' is not a member of
'TIdAttachment'
[C++ Error] Main.cpp(192): E2316 'ContentID' is not a member of
'TIdAttachment'

 There is no property ContentID in class TIdAttachment, that's why I
was   using ExtraHeaders->Values["Content-ID"] = ...
 

     Francesco




Remy Lebeau (TeamB) wrote:

> 
> <Francesco> wrote in message news:43aac389@newsgroups.borland.com...
> 
> >   I want to send a html mail using SMTP of Indy 9, when
> > i receive the mail i see the attaches but the mail is empty
> 
> Try this instead:
> 
>     MailMessage->From->Address = "mail@mail.com";
>     MailMessage->From->Name = "sender";
>     MailMessage->Recipients->EMailAddresses = "info@mail.com";
>     MailMessage->ContentType = "multipart/related;
> type=\"text/html\"";
> 
>     TIdText *HTML = new TIdText(MainMessage->MessageParts, NULL);
>     HTML->Body->LoadFromFile("c:\\mail.htm");
>     HTML->ContentType = "text/html";
> 
>     TIdAttachment *IImagePart = new
> TIdAttachment(MailMessage->MessageParts, "c:\\content.gif");
>     IImagePart->ContentID = "content.gif";
>     IImagePart->ContentType = "image/gif";
>     IImagePart->FileName = "content.gif";
> 
>     TIdAttachment *IImagePart2 = new
> TIdAttachment(MailMessage->MessageParts, "c:\\down.gif");
>     IImagePart2->ContentID = "down.gif";
>     IImagePart2->ContentType = "image/gif";
>     IImagePart2->FileName = "down.gif";
> 
>     TIdAttachment *IImagePart3 = new
> TIdAttachment(MailMessage->MessageParts, "c:\\topaug.gif");
>     IImagePart3->ContentID = "topaug.gif";
>     IImagePart3->ContentType = "image/gif";
>     IImagePart3->FileName = "topaug.gif";
> 
> 
> Gambit



-- 
Re: Send Html Email with Indy component doesn't work
#2933
Author: Remy Lebeau (TeamB)
Date: Fri, 23 Dec 2005 11:16
11 lines
1308 bytes
<Francesco> wrote in message news:43abaac3@newsgroups.borland.com...

>   [C++ Error] Main.cpp(180): E2316 'ContentID' is not a member
> of 'TIdAttachment'

Then you are using a very old build of Indy 9, because the ContentID
property has existed in Indy 9 for over 2 years now.


Gambit
Re: Send Html Email with Indy component doesn't work
#2934
Author: Francesco
Date: Fri, 23 Dec 2005 13:48
30 lines
1407 bytes

There was an old include file IdMessage.hpp, now update
but id doesn't work anyway, I receive the mail with attachments
but mail body is empty and if I try to see in html i don't see the code
i put before.


   Any idea?




Remy Lebeau (TeamB) wrote:

> 
> <Francesco> wrote in message news:43abaac3@newsgroups.borland.com...
> 
> >   [C++ Error] Main.cpp(180): E2316 'ContentID' is not a member
> > of 'TIdAttachment'
> 
> Then you are using a very old build of Indy 9, because the ContentID
> property has existed in Indy 9 for over 2 years now.
> 
> 
> Gambit



-- 
Re: Send Html Email with Indy component doesn't work
#2935
Author: Francesco
Date: Fri, 23 Dec 2005 13:55
9 lines
1155 bytes
This is the html of arrived mail:


<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN">
<HTML><HEAD>
<META http-equiv=Content-Type content="text/html;
charset=iso-8859-1"></HEAD>
<BODY></BODY></HTML>
Re: Send Html Email with Indy component doesn't work
#2937
Author: Remy Lebeau (TeamB)
Date: Fri, 23 Dec 2005 20:12
19 lines
1765 bytes
<Francesco> wrote in message news:43ac0e30@newsgroups.borland.com...

> There was an old include file IdMessage.hpp

Are you using BCB6, by chance?  BCB6 ships with Indy 8 pre-installed.  Indy
8 is not compatible with Indy 9 and must be removed from the machine before
Indy 9 will work properly.  There are removal instructions in Indy's
Knowledge Base.

> now update but id doesn't work anyway, I receive the mail
> with attachments but mail body is empty and if I try to see in
> html i don't see the code i put before.

Please show your actual code and the actual message data that is being
generated, headers and everything.


Gambit
Re: Send Html Email with Indy component doesn't work
#2945
Author: Francesco
Date: Tue, 27 Dec 2005 07:38
123 lines
4254 bytes
  Hi Remy,
  I'm using BCB 5 Pro, here follows my code and generated mail msg:



    MailMessage->From->Address = "mail@mail.com";
    MailMessage->From->Name = "sender";
    MailMessage->Recipients->EMailAddresses = "info@mail.com";

    MailMessage->ContentType = "multipart/related; type=\"text/html\"";

    TIdText *HTML = new TIdText(MailMessage->MessageParts, NULL);
    HTML->Body->LoadFromFile("c:\\mail.htm");
    HTML->ContentType = "text/html";


    TIdAttachment *IImagePart3 = new
    TIdAttachment(MailMessage->MessageParts, "c:\\topaug.gif");
    IImagePart3->ContentID = "topaug.gif";
    IImagePart3->ContentType = "image/gif";
    IImagePart3->FileName = "topaug.gif";

    TIdAttachment *IImagePart = new
    TIdAttachment(MailMessage->MessageParts, "c:\\content.gif");
    IImagePart->ContentID = "content.gif";
    IImagePart->ContentType = "image/gif";
    IImagePart->FileName = "content.gif";

    TIdAttachment *IImagePart2 = new
    TIdAttachment(MailMessage->MessageParts, "c:\\down.gif");
    IImagePart2->ContentID = "down.gif";
    IImagePart2->ContentType = "image/gif";
    IImagePart2->FileName = "down.gif";


    SMTP->Connect(1000);
    SMTP->Send(MailMessage);
    SMTP->Disconnect();

here mail.htm that stays on c:

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN">

<html>
<head>
	<title>Loveshopping auguri!</title>
</head>

<body>


	<table width="" align="center" border="0" cellSpacing=0 cellPadding=0>
<tr>
	<td><img src="cid:topaug.gif" width="662" height="155" alt=""
border="0"></td>
</tr>
<tr>
	<td><img src="cid:content.gif" width="662" height="341" alt=""
border="0"></td>
</tr>
<tr>
	<td valign="top"><img src="cid:down.gif" width="662" height="133"
alt="" border="0"></td>
</tr>
</table>


</body>
</html>


The mail arrives, I see the 3 img files attached but the body of the
mail is empty and if I show in html, this is what i have:

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN">
<HTML><HEAD>
<META http-equiv=Content-Type content="text/html;
charset=iso-8859-1"></HEAD>
<BODY></BODY></HTML>



If instead of using MailMessage->ContentType = "multipart/related;
type=\"text/html\""; I use MailMessage->ContentType = "text/html";
at least I see that is not able to link to images but the htm code is
the same I've sent.


   Any idea?








Remy Lebeau (TeamB) wrote:

> 
> <Francesco> wrote in message news:43ac0e30@newsgroups.borland.com...
> 
> > There was an old include file IdMessage.hpp
> 
> Are you using BCB6, by chance?  BCB6 ships with Indy 8 pre-installed.
> Indy 8 is not compatible with Indy 9 and must be removed from the
> machine before Indy 9 will work properly.  There are removal
> instructions in Indy's Knowledge Base.
> 
> > now update but id doesn't work anyway, I receive the mail
> > with attachments but mail body is empty and if I try to see in
> > html i don't see the code i put before.
> 
> Please show your actual code and the actual message data that is being
> generated, headers and everything.
> 
> 
> Gambit



-- 
Re: Send Html Email with Indy component doesn't work
#2948
Author: Remy Lebeau (TeamB)
Date: Wed, 28 Dec 2005 09:01
12 lines
1620 bytes
<Francesco> wrote in message news:43b0fd95@newsgroups.borland.com...

>   I'm using BCB 5 Pro, here follows my code and generated mail msg:

You did not show the message data that TIdMessage generates.  You showed
only the source HTML, which is not what I asked for.  Please show the RAW
DATA that TIdMessage generates and transmits over the socket.  That includes
the headers of the message, all MIME boundaries, etc.


Gambit
Re: Send Html Email with Indy component doesn't work
#2949
Author: Francesco
Date: Wed, 28 Dec 2005 09:56
25 lines
1662 bytes
Hi Remy I posted saved file on attachments group.

  Thanks, Francesco


Remy Lebeau (TeamB) wrote:

> 
> <Francesco> wrote in message news:43b0fd95@newsgroups.borland.com...
> 
> >   I'm using BCB 5 Pro, here follows my code and generated mail msg:
> 
> You did not show the message data that TIdMessage generates.  You
> showed only the source HTML, which is not what I asked for.  Please
> show the RAW DATA that TIdMessage generates and transmits over the
> socket.  That includes the headers of the message, all MIME
> boundaries, etc.
> 
> 
> Gambit



-- 
Re: Send Html Email with Indy component doesn't work
#2950
Author: Remy Lebeau (TeamB)
Date: Wed, 28 Dec 2005 17:31
18 lines
2007 bytes
<Francesco> wrote in message news:43b26f62@newsgroups.borland.com...

> Hi Remy I posted saved file on attachments group.

Are you sure that is the EXACT data that TIdMessage generates?  You did not
try to save the message data after it was received, did you?  The data that
you posted is malformed.  The top-level ContentType is wrong, and there is
no HTML at all.  I find it highly unlikely that Indy would produce such
malformed data, given the code you have shown.  So it was likely altered
during transmission.  I need you to show the original message data as it
appears BEFORE it is sent over the socket to the SMTP server.  Either use
one the TIdMessage.SaveTo...() methods, or attach one of the TIdLog...
components to TIdSMTP, or use an external packet sniffer such as Ethereal
(http://www.ethereal.com).


Gambit
Re: Send Html Email with Indy component doesn't work
#2952
Author: Francesco
Date: Thu, 29 Dec 2005 06:57
37 lines
2409 bytes

To get that file i put on code,
MailMessage->SaveToFile("c:\\email.txt"); before calling smtp->Send();
I try to reinstall Indy and creat a new project and export again data
file using log or savetofile again.

	Francesco








Remy Lebeau (TeamB) wrote:

> 
> <Francesco> wrote in message news:43b26f62@newsgroups.borland.com...
> 
> > Hi Remy I posted saved file on attachments group.
> 
> Are you sure that is the EXACT data that TIdMessage generates?  You
> did not try to save the message data after it was received, did you?
> The data that you posted is malformed.  The top-level ContentType is
> wrong, and there is no HTML at all.  I find it highly unlikely that
> Indy would produce such malformed data, given the code you have
> shown.  So it was likely altered during transmission.  I need you to
> show the original message data as it appears BEFORE it is sent over
> the socket to the SMTP server.  Either use one the
> TIdMessage.SaveTo...() methods, or attach one of the TIdLog...
> components to TIdSMTP, or use an external packet sniffer such as
> Ethereal (http://www.ethereal.com).
> 
> 
> Gambit
Re: Send Html Email with Indy component doesn't work
#2955
Author: Francesco
Date: Thu, 29 Dec 2005 09:55
54 lines
2773 bytes

Hi Remy,

I cleared Indy installation and reinstalled. I created a new
application and generated data files as you told me, unfortunately same
result as before. :-( I put everything on attachments group, have a
look plz.


	Thanks, Francesco




Francesco wrote:

> 
> 
> To get that file i put on code,
> MailMessage->SaveToFile("c:\\email.txt"); before calling smtp->Send();
> I try to reinstall Indy and creat a new project and export again data
> file using log or savetofile again.
> 
> 	Francesco
> 
> 
> 
> 
> 
> 
> 
> 
> Remy Lebeau (TeamB) wrote:
> 
> > 
> > <Francesco> wrote in message news:43b26f62@newsgroups.borland.com...
> > 
> > > Hi Remy I posted saved file on attachments group.
> > 
> > Are you sure that is the EXACT data that TIdMessage generates?  You
> > did not try to save the message data after it was received, did you?
> > The data that you posted is malformed.  The top-level ContentType is
> > wrong, and there is no HTML at all.  I find it highly unlikely that
> > Indy would produce such malformed data, given the code you have
> > shown.  So it was likely altered during transmission.  I need you to
> > show the original message data as it appears BEFORE it is sent over
> > the socket to the SMTP server.  Either use one the
> > TIdMessage.SaveTo...() methods, or attach one of the TIdLog...
> > components to TIdSMTP, or use an external packet sniffer such as
> > Ethereal (http://www.ethereal.com).
> > 
> > 
> > Gambit
Re: Send Html Email with Indy component doesn't work
#2958
Author: Francesco
Date: Thu, 29 Dec 2005 18:25
9 lines
1354 bytes
Hi Remy,

tested, finally works fine...

Thank you very much for your help and patience, I wish you a wonderful
2006.

     Francesco
Re: Send Html Email with Indy component doesn't work
#2957
Author: Remy Lebeau (TeamB)
Date: Thu, 29 Dec 2005 18:55
53 lines
3169 bytes
"Francesco" <.> wrote in message news:43b3c0ba@newsgroups.borland.com...

> I cleared Indy installation and reinstalled. I created a new
> application and generated data files as you told me, unfortunately
> same result as before. :-(

After much review, it appears that Indy 9 is not capable of sending the type
of message you are attempting unless you have *2* TIdText parts in the
MessageParts collection.  So add a TIdText of type 'text/plain' before the
HTML.  For example:

    MailMessage->From->Address = "iffbva@tin.it";
    MailMessage->From->Name = "iffbva@tin.it";
    MailMessage->Recipients->EMailAddresses = "iffbva@tin.it";

    // ADD THIS !!!
    TIdText *PlainText = new TIdText(MailMessage->MessageParts, NULL);
    PlainText->Body->Text = "This message contains HTML and images.";
    PlainText->ContentType = "text/plain";

    TIdText *HTML = new TIdText(MailMessage->MessageParts, NULL);
    HTML->Body->LoadFromFile(WPath+"\\email.htm");
    HTML->ContentType = "text/html";

    TIdAttachment *IImagePart = new TIdAttachment(MailMessage->MessageParts,
WPath+"\\content.gif");
    IImagePart->ContentID = "content.gif";
    IImagePart->ContentType = "image/gif";
    IImagePart->FileName = "content.gif";

    TIdAttachment *IImagePart2 = new
TIdAttachment(MailMessage->MessageParts, WPath+"\\down.gif");
    IImagePart2->ContentID = "down.gif";
    IImagePart2->ContentType = "image/gif";
    IImagePart2->FileName = "down.gif";

    TIdAttachment *IImagePart3 = new
TIdAttachment(MailMessage->MessageParts, WPath+"\\topaug.gif");
    IImagePart3->ContentID = "topaug.gif";
    IImagePart3->ContentType = "image/gif";
    IImagePart3->FileName = "topaug.gif";

    SMTP->Connect(1000);
    try {
        SMTP->Send(MailMessage);
    }
    __finally {
        SMTP->Disconnect();
    }


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