Page 1 of 1
reading outlook msg files
Posted: Fri Mar 15, 2013 3:55 pm
by normeus
I am new to Purebasic ( old to programming). I need to create a program that will read msg files. I looked at the specs of msg files and they are containers which I should be able to open with COM, I see there is a comate library. Has anyone used comate to open msg files and if so could you share an example. I am pressed for time so if I dont find a quick solution I will do it in perl but I would love to get some kind of solution with Purebasic.
( I searched for outlook in the forums but all I see is people trying to send emails from outlook. )
Thank you.
Re: reading outlook msg files
Posted: Fri Mar 15, 2013 6:28 pm
by Edwin Knoppert
On my site their is a download 'EMLreader' and it simply copies the .msg file to a .htm file and opens it in a webcontrol.
At least you can use this tool how it behaves..
Re: reading outlook msg files
Posted: Fri Mar 15, 2013 6:59 pm
by normeus
I don't have time right now but I will try it in about 3 hours
Thank you for the reply
Re: reading outlook msg files
Posted: Fri Mar 15, 2013 7:19 pm
by Edwin Knoppert
My website's url was incorrect, it's corrected now..
Re: reading outlook msg files
Posted: Mon Mar 18, 2013 6:17 am
by normeus
Thanks Edwin Knoppert, however; your EMLreader is a program with no source so I cannot see what is going on. I looked into the whole format of MSG files and if I had ( when I have ) time, I Will create a MSG reader in purebasic. ( don't hold your breath)
in the mean time here is the code needed for COMatePLUS.pbi to open outlook read MSG file and export as RTF or TXT
Code: Select all
EnableExplicit
; partial copy of comateplus outlook example
; you need MS Outlook for this to work (not Outlookexpress)
IncludePath "C:\Program Files (x86)\PureBasic\comate\"
XIncludeFile "COMatePLUS.pbi"
Define.COMateObject OutlookObject, olMsg
Define filei.s="G:\emlmsg\oneof5000.msg"; input msg file
Define fileo.s="G:\emlmsg\outas-rtf-or-txt.rtf" ; hard coded extension, should be changed acording to outformat
OutlookObject = COMate_CreateObject("Outlook.Application")
;there might be other formats but I just needed rtf and txt
#outFormatTXT = 0
#outFormatRTF = 1
If OutlookObject
olMsg = OutlookObject\GetObjectProperty("CreateItemFromTemplate('"+filei+"')")
If olMsg
olmsg\Invoke("SaveAs('" + fileo+ "', "+#outFormatRTF+")")
olMsg\Release()
Else
MessageRequester("Sorry", COMate_GetLastErrorDescription())
EndIf
OutlookObject\Release()
Else
MessageRequester("Sorry - CreateObject", COMate_GetLastErrorDescription())
EndIf
If you know of any problems with this code, let me know. ( and also for enhancements)
Norm.
Re: reading outlook msg files
Posted: Mon Mar 18, 2013 6:48 pm
by Edwin Knoppert
The criteria for me was different, a certain version of Outlook didn't eat msg files anymore and i wrote this tool for someone at the office.
The code is not really important here because i explained that i renamed the filename and then opened in an Internet control.
If you rename the file you can use IE to open it, that's all it does.
If you want a real conversion and Outlook is present you may be fine as well.
Pick your option here

Re: reading outlook msg files
Posted: Fri Mar 29, 2013 3:09 am
by normeus
So my sample program [see previous post ] was doing a great job until I got to a folder with MSG files that were saved as non-unicode. The funny part is that I did not compile my program as unicode so I don't see how it was working before. I need to read those non-unicode files ( about 680 ). is there any extra settings in COMatePLUS to disable unicode? ( the setting for unicode is not enabled in purebasic )
I am using PB 5.11 x86 , COMatePLUS. Version 1.2 released 09th July 2010.
Thank you.
norm
Re: reading outlook msg files
Posted: Fri Mar 29, 2013 6:12 pm
by normeus
so I couldn't figure out why the program did not read non-unicode messages.
using the same basic code I used "autoitscript" and it worked and for the sake of clarity here is autoit's code
Code: Select all
#include <Outlookex.au3> ;this is an extra library that has to be downloaded "OutlookEX UDF" from autoitscript forum
$oOutlook = ObjCreate("Outlook.Application")
$filei="D:\emlmsg\DailyProduction.msg" ; my dummy input test file
$oItem = _OL_ItemCreate($oOutlook, $olMailItem, "*", $filei) ;$olMailItem = Type of item to create. Is defined by the Outlook OlItemType enumeration
$oItem.SaveAs("c:\newfilename.rtf", 1) ; doing save as rtf which is 1 on the last parameter