I have a folder with thousands of Outlook .msg files.
I'd like to know if it's possible to write a VB Script that can read the sender and receiver from each file, and move the .msg file to a folder based on this info?
Thanks
You shouldn't ask yes/no questions unless you expect the answer to be either "yes" or "no".
Set ol = CreateObject("Outlook.Application")
Set fso = CreateObject("Scripting.FileSystemObject")
For Each f In fso.GetFolder("C:\some\folder").Files
If LCase(fso.GetExtensionName(f)) = "msg" Then
Set msg = ol.CreateItemFromTemplate(f.Path)
WScript.Echo msg.Sender.Name
For Each rcpt In msg.Recipients
WScript.Echo rcpt.Name
Next
End If
Next
For reading the contents of a .msg file, I have used the following approach.
Script:
Dim OL : Set OL=CreateObject("Outlook.Application")
Dim Msg ':Set Msg= CreateObject("Outlook.MailItem")
Set Msg = OL.CreateItemFromTemplate("C:\test.msg")
'MsgBox Msg.Subject
Msg.saveAs "C:\test.txt", olDoc
'The above statement will save the contents of .msg file into the designate .txt file
Set OL = Nothing
Set Msg = Nothing
Once the .txt file is created use it as required for your computations.