這邊紀錄下利用 VBscript 來
- 讀取本地端的 Outlook msg 檔案資訊,移如信件的收信者資訊。
- 讀取本地 Outlook 收件夾(或刪除的郵件、寄件備份等資料夾)裡的信件資訊。
<package> <job id=XXX> <script language="VBScript"> parOutlookMsgFile("D:\testOutlookMail.msg") parseOutlookInboxFolder(6) ''''''''''''''''''''''''''''''''''''''''''''''''''''' Sub parOutlookMsgFile(msgFilePath) Dim objOutlook 'Dim objInBoxFolder 'Dim objNameSpace Set objOutlook = CreateObject("Outlook.Application") 'Set objNameSpace = objOutlook.GetNamespace("MAPI") 'Set objInBoxFolder = objNameSpace.GetDefaultFolder(6) Dim mail, recips, recip, email_single, pa Set mail = objOutlook.CreateItemFromTemplate(msgFilePath) Set recips = mail.Recipients For Each recip In recips Set pa = recip.PropertyAccessor email_single = pa.GetProperty("http://schemas.microsoft.com/mapi/proptag/0x39FE001E") WScript.Echo "Receiver Name: " & recip.Name & ", Receiver Email: " & email_single & ", type: " & recip.Type Next End Sub ''''''''''''''''''''''''''''''''''''''''''''''''''''' Sub parseOutlookInboxFolder(inboxFolderType) 'inboxFolderType: ' received mail inbox: 6 ' deleted mail inbox : 3 ' sent mail inbox : 5 Dim objOutlook, objInBoxFolder, objNameSpace, objMailItems Set objOutlook = CreateObject("Outlook.Application") Set objNameSpace = objOutlook.GetNamespace("MAPI") Set objInBoxFolder = objNameSpace.GetDefaultFolder(inboxFolderType) Set objMailItems = objInBoxFolder.Items Dim i i = 1 Dim totalMailCount totalMailCount = objMailItems.count While i <= totalMailCount Set objMail = objMailItems.Item(i) WScript.Echo objMail.Subject i = i + 1 Wend End Sub </script> </job> </package>
說明:
程式碼中有兩個函式,分別是用來讀取單一 Msg 檔資訊的 parOutlookMsgFile()
和 讀取 Outlook 收件夾(或刪除的郵件、寄件備份等資料夾)裡的信件資訊的 parseOutlookInboxFolder()。
在 parOutlookMsgFile() 中,recip.Type 可能有 1 或 2 兩種值,
Type = 1 代表一般收件者,
Type = 2 代表 cc 副本的收件者。
parseOutlookInboxFolder() 函式可以接收收件夾 type (OlDefaultFolders 形別) 的值,
其中 6 代表收件夾,
3 代表刪除的郵件,
沒有留言 :
張貼留言