使用VB脚本读取.msg文件的内容

时间:2013-07-30 09:10:39

标签: vbscript msg

我有一个包含数千个Outlook .msg文件的文件夹。

我想知道是否可以编写一个可以从每个文件中读取发件人和收件人的VB脚本,并根据此信息将.msg文件移动到文件夹中?

由于

2 个答案:

答案 0 :(得分:2)

除非您希望答案是“是”或“否”,否则不应该回答是/否问题。

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

答案 1 :(得分:0)

为了读取.msg文件的内容,我使用了以下方法。

  1. 使用outlook对象
  2. 为msg文件使用CreateItemFromTemplate
  3. 使用此outlook对象将数据保存为.txt文件
  4. 创建.txt文件后,请阅读并使用所需的数据
  5. 脚本:

    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
    

    创建.txt文件后,请根据您的计算使用它。