Outlook邮件项属性访问者返回Bad Strings

时间:2017-10-27 05:58:45

标签: vba properties outlook outlook-vba

我正在尝试使用PropertyAccessor显示多个MailItem属性的值,但我得到的所有内容都是不可打印的字符。

我没有发现有类似问题的帖子。

Private Const PRMessageID = "http://schemas.microsoft.com/mapi/proptag/0x1035001E"
Private Const PRConvIndex = "http://schemas.microsoft.com/mapi/proptag/0x00710102"
Private Const PRSenderEID = "http://schemas.microsoft.com/mapi/proptag/0x0C190102"
Private Const PRParentEID = "http://schemas.microsoft.com/mapi/proptag/0x0E090102"
Private Const PRStoreEnID = "http://schemas.microsoft.com/mapi/proptag/0x0FFB0102"
Private Const PR__EntryID = "http://schemas.microsoft.com/mapi/proptag/0x0FFF0102"
Private Const PRRecordKey = "http://schemas.microsoft.com/mapi/proptag/0x0FF90102"
Private Const PRStrRecKey = "http://schemas.microsoft.com/mapi/proptag/0x0FFA0102"
Private Const PRSearchKey = "http://schemas.microsoft.com/mapi/proptag/0x300B0102"

    Public Function AssignMailIDS(oMail As Outlook.MailItem) As String
        AssignMailIDS = oMail.ConversationIndex

    '    oMail.PropertyAccessor.SetProperty PropNameSpace, AssignMailIDS
    '
    '    Debug.Print oMail.PropertyAccessor.getProperty(PropNameSpace)

        oMail.ItemProperties.Add("OriginalConvIdx", olText, True) = AssignMailIDS

        Debug.Print "+++++"
        Debug.Print "-----"
        Debug.Print oMail.UserProperties("OriginalConvIdx")
        Debug.Print "Message ID " & GetItemID(oMail, PRMessageID)
        Debug.Print "Convers ID " & GetItemID(oMail, PRConvIndex)
        Debug.Print "Sender EID " & GetItemID(oMail, PRSenderEID)
        Debug.Print "Parent EID " & GetItemID(oMail, PRParentEID)
        Debug.Print "Store EnID " & GetItemID(oMail, PRStoreEnID)
        Debug.Print "Entry   ID " & GetItemID(oMail, PR__EntryID)
        Debug.Print "Record Key " & GetItemID(oMail, PRRecordKey)
        Debug.Print "StrRec Key " & GetItemID(oMail, PRStrRecKey)
        Debug.Print "Search  ID " & GetItemID(oMail, PRSearchKey)
    End Function

    Public Function GetItemID(oItem As MailItem, sID As String) As String
        On Error Resume Next
        GetItemID = "<Non Existant>"
        GetItemID = oItem.PropertyAccessor.getProperty(sID)
    End Function

        Set oOLapp = OpenOutlook()

        Set oMapi = oOLapp.GetNamespace("MAPI")
        Set oSentFolder = oOLapp.GetNamespace("MAPI").Folders(oMapi.DefaultStore.DisplayName).Folders("Sent Items")

        Set oItems = oSentFolder.Items
        oItems.Sort "[SentOn]", True
        Set oItem = oItems(1) ' Get latest sent item
        Debug.Print "-----"
        Debug.Print "Message ID " & GetItemID(oItem, PRMessageID)
        Debug.Print "Convers ID " & GetItemID(oItem, PRConvIndex)
        Debug.Print "Sender EID " & GetItemID(oItem, PRSenderEID)
        Debug.Print "Parent EID " & GetItemID(oItem, PRParentEID)
        Debug.Print "Store EnID " & GetItemID(oItem, PRStoreEnID)
        Debug.Print "Entry   ID " & GetItemID(oItem, PR__EntryID)
        Debug.Print "Record Key " & GetItemID(oItem, PRRecordKey)
        Debug.Print "StrRec Key " & GetItemID(oItem, PRStrRecKey)
        Debug.Print "Search  ID " & GetItemID(oItem, PRSearchKey)
        sItemConvIdx = oItem.UserProperties("OriginalConvIdx")

这导致以下输出到调试器窗口:

+++++
-----
01D34EE4AAEC61381400E9CB4836BA2932216C015C25
Message ID 
Convers ID ????????U+
Sender EID <Non Existant>
Parent EID <Non Existant>
Store EnID <Non Existant>
Entry   ID <Non Existant>
Record Key <Non Existant>
StrRec Key ????????
Search  ID <Non Existant>
-----
Message ID 
Convers ID ???????????
Sender EID   ???????   ???????????????????????????
Parent EID   ???????????????? ?? 
Store EnID   ??????? ?????    ???????? ???????????????????????????????????????????8??T   Walter.ZAMBOTTI@police.wa.gov.au  
Entry   ID   ???????????????? ?? ????????A?? 
Record Key   ????????????????A?? 
StrRec Key ????????
Search  ID ????????

我原本试图获取消息ID但是当它是空白时我感到很惊讶所以我尝试检索其他值并且没有发现任何有用的。

任何想法都赞赏!

1 个答案:

答案 0 :(得分:1)

改为使用

Public Function GetItemID(oItem As MailItem, sID As String) As String
    On Error Resume Next
    GetItemID = "<Non Existant>"
    GetItemID = oItem.PropertyAccessor.BinaryToText(oItem.PropertyAccessor.getProperty(sID))
End Function

当然,返回的一些字符串实际上是字符串,而其他字符串则需要转换。这意味着你需要使上面的函数接受一个可选的IsBinary标志,这样你就可以选择是否转换。