Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Chriss Miller on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

reading msg file? 1

Status
Not open for further replies.

LindaCung

Programmer
Joined
Apr 22, 2008
Messages
5
Hi, I am new to this forum. I tried do search on using vba to read msg files I drag out from outlook. The only ones I found were reading the msg files as regular text file. I also tried searching on the web, but without any luck :(. i am wondering if there an expert out there who can let me know if there's any other way to deal with msg files? What I wanted to do is sharing emails in a PST file. I am trying to save the sender, reciever, subject and body into SQL and be able to do search easier for multiple users. I noticed when I open the PST, it's locked. Using third party software to share is not an open option for me. So I have to try store everything in SQL and let users be able to search thro the emails in the PST files. I would be appreciated if anyone can point me to the right direction; eighter on reading msg (not as text file) or a better way to share emails in the PST file. Thank you in advance.

best regards,

Linda
 
Thank you kindly for your reply Remou. I already have everything sort out. What I did was drag all the message out from the PST file and read the properties of each msg file. using the msdn library example. It's actually not so bad. My only question left right now is every time i access try read a msg file, outlook gives me a warning message relating something is trying to access the server. I am still doing searches on the issue. I will post result when I found out how. The code block i have below reads all msg files and gets the properties off the file and stores into a table in sql server. I hope anyone has any use to the code :)


Code:
Public Sub getFiles(Path As String)
    Dim fso, f, fc, f1, sqlStr
    Dim myitem As Outlook.MailItem

    Set fso = CreateObject("Scripting.FileSystemObject")
    Set f = fso.GetFolder(Path)

    'read all files in present folder
    Set fc = f.Files
    For Each f1 In fc
        Set myitem = Outlook.Application.CreateItemFromTemplate(Path & "\" & f1.Name)
        
        sqlStr = "insert into tblEmails (FileName, Sender, ReceiverEmail, Receiver, ReceivedDate, Subject) Values ('" & Replace(Path & "\" & f1.Name, "'", "''") & "', '" & Replace(myitem.SenderName, "'", "''") & "', '" & myitem.SenderEmailAddress & "', '" & Replace(myitem.To, "'", "''") & "', '" & myitem.ReceivedTime & "', '" & myitem.Subject & "')"

        DoCmd.RunSQL sqlStr
    Next

    'read all subfolders
    Set fc = f.subfolders
    For Each f1 In fc
        getFiles (f & "\" & f1.Name)
    Next
    
    'Set fso = Nothing
    'Set f = Nothing
End Sub
 
Hello again everyone, does anyone know how to turn off that pop up when you use MAPI? I mean the pop up asking for your permission to use the outlook session. I tried searching, but not sure what to search for. if anyone can answer, i would be much appreciated. Thank you
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top