graga
asked on
Reading and displaying email body using Indy TIdMessage
Hi Experts,
I'm building a simple email client application.
I retrieve message with:
IdPOP3.Retrieve(iMessageCo unt, NewMessage)
but I'm having problems displaying the message body. I'm using sample code from Indy but id displays much more information that is stored in the message body, for example:
================
--_NextPart_2altrfkindysad vnqw3neras df
Content-Type: text/plain; charset"iso-8859-1"
Content-Transfer-Encoding: quoted-printable
this is a test message
================
followed by more stuff.
What I want is something like any other email client, select email and display content of email body in correct format.
I need it urgently so 500 points for a complete solution
I'm building a simple email client application.
I retrieve message with:
IdPOP3.Retrieve(iMessageCo
but I'm having problems displaying the message body. I'm using sample code from Indy but id displays much more information that is stored in the message body, for example:
================
--_NextPart_2altrfkindysad
Content-Type: text/plain; charset"iso-8859-1"
Content-Transfer-Encoding:
this is a test message
================
followed by more stuff.
What I want is something like any other email client, select email and display content of email body in correct format.
I need it urgently so 500 points for a complete solution
Sorry, I now see that you're posting the .Retrieve code you used... the code should still apply, though. The BODY property of the message isn't really where you want to get the body. The messageparts contains a TIDText object which contains the body.
ASKER
Thank you Validor,
This is the code I'm using. I store the message in a database first in a blobfield and then retrieve. I think that's where I may have the error. But, when I decoded the message straight away from POP3 the code works okay for plain text messages but messages stored in HTML don't work and I need to display it in the correct format. Any ideas?
This is the code I'm using. I store the message in a database first in a blobfield and then retrieve. I think that's where I may have the error. But, when I decoded the message straight away from POP3 the code works okay for plain text messages but messages stored in HTML don't work and I need to display it in the correct format. Any ideas?
The definition of an email message is as follows:
header
. (a line with only a dot)
body
The header consists of name value pairs where the name part is separated from the value(s) with a colon (:)
Normally the body and header are separated by TIdMessageClient.ReceiveHe ader
>> if ((Length(AAltTerm) = 0) and (Result = '.')) or
>> ({APR: why? (Length(AAltTerm) > 0) and }(Result = AAltTerm)) then begin
My Indy version has the code above. It has a small commented part after APR. Maybe it is not commented in your version? Or maybe it is as well and it will work if you uncomment it.
Anyway if you want to correct the way the header is separated from the body this is the place to alter.
Could you post the "raw" message here you test with here? I mean header and body together (like when it is posted using SMTP). Then I could help you alter the Indy code correctly.
Regards Jacco
header
. (a line with only a dot)
body
The header consists of name value pairs where the name part is separated from the value(s) with a colon (:)
Normally the body and header are separated by TIdMessageClient.ReceiveHe
>> if ((Length(AAltTerm) = 0) and (Result = '.')) or
>> ({APR: why? (Length(AAltTerm) > 0) and }(Result = AAltTerm)) then begin
My Indy version has the code above. It has a small commented part after APR. Maybe it is not commented in your version? Or maybe it is as well and it will work if you uncomment it.
Anyway if you want to correct the way the header is separated from the body this is the place to alter.
Could you post the "raw" message here you test with here? I mean header and body together (like when it is posted using SMTP). Then I could help you alter the Indy code correctly.
Regards Jacco
Which version of Indy are you using?
Delphi 6 = version 8
Delphi 7 = version 9
Delphi 8 = version 10
If using Version 10, are you using the version that came with Delphi, or did you download the latest? If not, download the latest. Either way, version 10 is in beta and may have a bug.
If you are using the Indy 10 .NET version for non-delphi environments such as C#, please point that out as well.
Delphi 6 = version 8
Delphi 7 = version 9
Delphi 8 = version 10
If using Version 10, are you using the version that came with Delphi, or did you download the latest? If not, download the latest. Either way, version 10 is in beta and may have a bug.
If you are using the Indy 10 .NET version for non-delphi environments such as C#, please point that out as well.
ASKER
I'm using Indy 9.011 on D5
Have you checked the TIdMessageClient.ReceiveHe ader in your version? Can you show what it reads?
ASKER
My TIdMessageClient.ReceiveHe ader is exactly same as yours.
I have also noted that when using INDY demo of Email Client, the message also displays incorrectly.
I have also noted that when using INDY demo of Email Client, the message also displays incorrectly.
Can you paste the header here?
ASKER
OK, what I have found so far:
If ContentType is text_plain, the message body text is in IdMessage.Body - simple.
When ContentType is for example multipart/mixed, then everything is stored in MessageParts.
As I understand, IdMessage does not decode MessageParts but dumps everything as text.
The decoding is probably done by IDMessageDecoder or IDMessageDecoderMIME but so far I have no idea how to use it.
If ContentType is text_plain, the message body text is in IdMessage.Body - simple.
When ContentType is for example multipart/mixed, then everything is stored in MessageParts.
As I understand, IdMessage does not decode MessageParts but dumps everything as text.
The decoding is probably done by IDMessageDecoder or IDMessageDecoderMIME but so far I have no idea how to use it.
Please email me a message such as the one you are having trouble with. I'll try it and see if I get the same result so that I can better see what the problem is.
validar
-a-t-
netscape.net.
validar
-a-t-
netscape.net.
ASKER
I have installed a Clever Internet Suite set of components and they do exactly what I want.
Thank you for trying
Thank you for trying
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
//get message and put into MSG
ShowStatus('Retrieving message "' + lvHeaders.Selected.SubItem
POP.Retrieve(lvHeaders.Sel
statusbar1.Panels[0].text := lvHeaders.Selected.SubItem
//Setup fields on screen from MSG
From.Caption := Msg.From.Text;
Recipients.Caption := Msg.Recipients.EmailAddres
Cc.Caption := Msg.CCList.EMailAddresses;
Subject.Caption := Msg.Subject;
Date.Caption := FormatDateTime('dd mmm yyyy hh:mm:ss', Msg.Date);
Receipt.Caption := Msg.ReceiptRecipient.Text;
Organization.Caption := Msg.Organization;
Priority.Caption := IntToStr(Ord(Msg.Priority)
//Setup attachments list
ShowStatus('Decoding attachments (' + IntToStr(Msg.MessageParts.
for intIndex := 0 to Pred(Msg.MessageParts.Coun
begin
if (Msg.MessageParts.Items[in
begin //general attachment
pnlAttachments.visible := true;
li := lvMessageParts.Items.Add;
li.ImageIndex := 8;
li.Caption := TIdAttachment(Msg.MessageP
li.SubItems.Add(TIdAttachm
end
else
begin //body text
if Msg.MessageParts.Items[int
begin
Memo1.Lines.Clear;
Memo1.Lines.AddStrings(TId
end
end;
end;