Board index » cppbuilder » TIdMessage text+(html+graphic)

TIdMessage text+(html+graphic)


2006-09-23 05:25:10 PM
cppbuilder95
Turbo C++ Indy9
Trying to use TIdmessage and TIdSMTP to compose and send mails.
For mails who consist of
-text only
-html only
-text+html
-text+attachment
-text+html+attachment
all works like expected. I mean the Content-Type's
and boundaries are the same as when composed and sent
with thunderbird.
-text+(html+graphic) I cannot handle this like it should.
First: the Content-Type's are reversed. Thunderbird does it like
/*
Subject: thunderbird text+(html+graphic)
Content-Type: multipart/alternative;
boundary="------------080600050801000102040000"
This is a multi-part message in MIME format.
--------------080600050801000102040000
Content-Type: text/plain; charset=us-ascii; format=flowed
Content-Transfer-Encoding: 7bit
Hello you. Here a picture:
--------------080600050801000102040000
Content-Type: multipart/related;
boundary="------------050907000600090804020203"
*/
But here I get the multipart/related first. Does not matter
what I do with Content-Type
As there are two Content-Type's I wonder how I should tell that
to TIdMessage.
The mailreaders Thunderbird and OE (if the message is receied)
do not care about the reversing.
Second: If I send it to mij gmail.com account the message
is received. If I send it to the account at my provider the
message is not received. No exceptions thrown and the .eml
produced.
Here the code I tried:
AnsiString GraphicFileName = "pluis.gif";
AnsiString Text =
"How are you?\r\n"
"I'm doing well.\r\n"
"Please have a ..."
;
AnsiString HtmlTextWithGraphic =
"<html><body>\r\n<font color=\"blue\" size=\"+2\">"
"How are you?<br>\r\n"
"<img src=\"cid:" + GraphicFileName + "\" />"
"I'm doing well.<br>\r\n"
"Please have a ..."
"</font></body></html>\r\n"
;
void __fastcall TForm2::Button6Click(TObject *Sender)
{
// Text+(Html+Graphic)
TIdMessage *IdMessage = new TIdMessage ( this );
TIdText *text1 = new TIdText(IdMessage->MessageParts, NULL);
text1->Body->Text = Text;
text1->ContentType = "text/plain";
TIdText *text2 = new TIdText(IdMessage->MessageParts, NULL);
text2->Body->Text = HtmlTextWithGraphic;
text2->ContentType = "text/html";
AnsiString FilePath = ExtractFilePath(ParamStr(0)) + GraphicFileName;
TIdAttachment *IdAttachment = new TIdAttachment(
IdMessage->MessageParts, FilePath );
IdAttachment->ContentType = GetMIMETypeFromFile(FilePath);
IdAttachment->FileName = GraphicFileName;
IdAttachment->ContentID = GraphicFileName;
IdMessage->Subject = Subject + " Text+(Html+Graphic)";
IdMessage->From->Address = FromAddress;
IdMessage->From->Name = FromName;
IdMessage->Recipients->EMailAddresses = EMailAddresses;
IdMessage->ContentType = "multipart/related; type=\"multipart/alternative\"";
IdMessage->SaveToFile("IdMessage.6.eml", false);
IdSMTP->Host = Host;
IdSMTP->Port = Port;
IdSMTP->Connect(1000);
IdSMTP->Send(IdMessage);
IdSMTP->Disconnect();
delete IdMessage;
}
So if someone could give me a hand?
Hans.
 
 

Re:TIdMessage text+(html+graphic)

"Hans Galema" < XXXX@XXXXX.COM >wrote in message
Quote
-text+(html+graphic) I cannot handle this like it should.
Indy 9 has never been able to support that particular format. Indy 9's MIME
capabilities are very limited. It simply canot handle the more complex MIME
hierarchies that are being used nowadays. You will have to continue using
"text+html+attachment" instead, or format the nested MIME manually, or else
upgrade to Indy 10.
Quote
As there are two Content-Type's I wonder how I should tell
that to TIdMessage.
The only way to do that with Indy 9 is to put the entire "multipart/reated"
block into a text attachment. You will not be able to create such a
message using individual message parts alone. For example:
IdMessage1->Subject = "indy text+(html+graphic)"
IdMessage1->ContentType = "multipart/alternative";
TIdText *pText = new TIdText(IdMessage1->MessageParts, NULL);
pText->ContentType = "text/plain"; charset=us-ascii; format=flowed";
pText->ContentTransfer = "7bit";
pText->Body->Texzt = "Hello you. Here a picture:";
pText = new TIdText(IdMessage1->MessageParts, NULL);
pText->Content-Type = "multipart/related;
boundary=\"------------myboundary\"";
pText->Body->Text = "the entire multipart/related content goes here";
Quote
If I send it to mij gmail.com account the message is received.
If I send it to the account at my provider the message is not
received. No exceptions thrown and the .eml produced.
If Send() returns without throwing an exception, then the provider has
accepted the message and is then responsible for delivering it. There is
nothing Indy can do to help the provider once Send() has been called. If
the provider cannot deliver the message, then it will send an error email to
the return address of the message explaining why the message could not be
delivered.
Gambit
 

Re:TIdMessage text+(html+graphic)

Remy Lebeau (TeamB) wrote:
Quote
>-text+(html+graphic) I cannot handle this like it should.

Indy 9 has never been able to support that particular format.
But as said: It (mostly) sends a message that is interpreted
by thunderbird and OE as intended.
Quote
.. or else
upgrade to Indy 10.
As you will know that is currently not supported for C++Builder.
But following your advise I tried the IDE to grab Indy10
instead of Indy9 and did the following:
Menu Tools | Options | Environment Options | C++ Options | Paths and Directories
SearchPath (choose one):
$(BDS)\Include\Indy9;$(BDS)\Lib\Indy9
$(BDS)\Include\Indy10;$(BDS)\Lib\Indy10
Browsing Path(choose one):
$(BDS)\source\Win32\Indy9
$(BDS)\source\Indy10
But having applied these changes then from IdWinSock2.hpp
there is the warning:
//-- user supplied -----------------------------------------------------------
#error Indy 10 does not currently support C++Builder
Q.E.D.
Quote
>As there are two Content-Type's I wonder how I should tell
>that to TIdMessage.

The only way to do that with Indy 9 is to put the entire "multipart/reated"
block into a text attachment. You will not be able to create such a
message using individual message parts alone. For example:
OK. Thanks for the example.
Quote
If Send() returns without throwing an exception, then the provider has
accepted the message and is then responsible for delivering it. There is
nothing Indy can do to help the provider once Send() has been called.
OK. That is fair.
Quote
If
the provider cannot deliver the message, then it will send an error email to
the return address of the message explaining why the message could not be
delivered.
But it does not here in the case I described.
Hans.
 

{smallsort}