Need help, retrieving decoded message body

Jun 27, 2013 at 6:43 PM
Hi

Can someone please help me to get this to work? My objective is to store the the full email content into a db and then retrieve it and display in asp.net page with correct formatting. This is what i am doing

string originalMessage = msg.GetAsString();

then save this string to db

now i don't know how to decode this string back so i can display in the asp.net page in a nice format include link for attachment just like if you are reading an normal email.

Am i on right track or i should do something different?

Thanks a lot
Coordinator
Jun 28, 2013 at 8:23 AM
Edited Jun 28, 2013 at 8:24 AM
Hi Vnwind,

if you want to get the decoded message body, please use the GetDecodedBody method and not GetAsString. For more details see the documentation page.


Best regards,

Pavel Azanov
Jul 2, 2013 at 4:34 PM
Hi Pavel

Thanks for helping. I went over and over documentation and source code. I still could not figure out how to accomplished my goal where I would like to store the email in the database and display it again in a nice html format :-( (sorry for my incompetent ). With GetDecodedBody, i only get the body of email but not the attachments. If I used GetAsString then i got the attachment but it is in binary code. Is there a way for me to decoded the string from GetAsString back to a readable email format?

Thanks again for any help

Cheers
Coordinator
Jul 2, 2013 at 5:17 PM
Edited Jul 2, 2013 at 5:26 PM
Hi Vnwind,

First of all, we should make clear how you want to store and read back the messages including attachments. If you took a look at the sample application, you saw that it is displaying the message body returned by the GetDecodedBody method in a WebBrowser control. The attachments and the inline attachments (e.g images in messages) are cached on disk.

In general you have two options:
  1. You store the information of your message in the database, such fields as Sender, Recipient, Date, Subject and the decoded body (use GetDecodedBody method). At same time you have a table with information on attachments, including the file name, file type, file encoding and the binary data. (You can get this all from the Attachments/InlineAttachments collection) of a message.
  2. Second option differs only in the way you save the attachments. You can cache the attachments to disk and save only the path information in database.
Personally I prefer the second option.

After you saved the messages this way, you can just do same as in the sample application: read the data from the database, and display the saved decoded body in a WebBrowser control, and bind the attachments.

Hope could help you with the idea.

When I have more time I'll extend the sample application with the option on storing messages into a database.


Greets,

Pavel