How to extract .msg file from Outlook to TrichView

General TRichView support forum. Please post your questions here
Post Reply
tobyfleming
Posts: 1
Joined: Mon Oct 02, 2023 2:22 am

How to extract .msg file from Outlook to TrichView

Post by tobyfleming »

Hello, Can you guide me on how to extract .msg file from Outlook to Trichview? I'm looking for how to do it but without success. Thanks
Sergey Tkachenko
Site Admin
Posts: 17557
Joined: Sat Aug 27, 2005 10:28 am
Contact:

Re: How to extract .msg file from Outlook to TrichView

Post by Sergey Tkachenko »

TRichView does not include code for parsing MSG files.
However, if you have Outlook installed, you can use Outlook COM object to open MSG file in TRichViewEdit.

There is a demo showing how to compose email in TRichViewEdit and send or save it using Outlook object:
https://www.trichview.com/forums/viewtopic.php?t=10734

Here is the code for opening MSG file (file choosing and error checking are skipped for simplicity). You can call this code on button click in this demo:

Code: Select all

var
   MI: _MailItem;
   Stream: TMemoryStream;
   Body: UnicodeString;
begin
   MI := App.Session.OpenSharedItem(FILENAME) as _MailItem;
   txtSubject.Text := MI.Subject;

   Stream := TMemoryStream.Create;
   Body := MI.HTMLBody;
   Stream.WriteBuffer(PWideChar(Body)^, Length(Body) * sizeof(WideChar));
   Stream.Position := 0;
   RichViewEdit1.Clear;
   RichViewEdit1.DeleteUnusedStyles(True, True, True);
   RichViewEdit1.LoadHTMLFromStream(Stream, '', 1200 {UTF-16});
   RichViewEdit1.Format;
   Stream.Free;
MI.HTMLBody always returns HTML for the email object (even if this is a plain text email; in this case, the object gets HTML from a plain text).
The code above displays email body and subject. You can also check other fields of MI (such as Recipients and Sender)
Post Reply