How to get Message-Id or Header in “Sent Items” Folder in Outlook-2007 in VBA

五迷三道 提交于 2019-12-12 12:24:54

问题


This is a sub-question of this main question

I am able to loop get the internet header of other folders using the following functions

Sub testing()
Dim ns As Outlook.NameSpace
Dim folder As MAPIFolder
 Dim item As MailItem
Set ns = Session.Application.GetNamespace("MAPI")
Set folder = ns.GetDefaultFolder(olFolderInbox)

 For Each item In folder.Items

    If (item.Class = olMail) Then
        GetInetHeaders item
    End If
Next item

End Sub

Function GetInetHeaders(olkMsg As MailItem) As String

    ' Purpose: Returns the internet headers of a message.'

    ' Written: 4/28/2009'

    ' Author:  BlueDevilFan'

    ' Outlook: 2007'

    Const PR_TRANSPORT_MESSAGE_HEADERS = "http://schemas.microsoft.com/mapi/proptag/0x007D001E"

    Dim olkPA As Outlook.PropertyAccessor

   Set olkPA = olkMsg.PropertyAccessor

    GetInetHeaders = olkPA.GetProperty(PR_INTERNET_MESSAGE_ID)

    Debug.Print olkMsg.Subject
    Debug.Print GetInetHeaders


    Set olkPA = Nothing

End Function

But Not working on the "Sent Items" folder, any one have experience or reference for this?

FAIL the Property returns nothing

Sub testing2()
Dim item As MailItem
Set Store = Application.GetNamespace("MAPI").Folders
  For Each StoreFolder In Store

      For i = 1 To StoreFolder.Folders.Count
        If StoreFolder.Folders(i).Name = "Sent Items" Then
            For Each item In StoreFolder.Folders(i).Items
                If (item.Class = olMail) Then
                    GetInetHeaders item
                End If
            Next item
            Exit For
        End If
      Next
    Exit For

  Next
End Sub

EDIT If it's not achievable, I can BCC myself in the email.


回答1:


PR_TRANSPORT_MESSAGE_HEADERS is only available on the messages received from a POP3 account. It is never set on the outgoing messages. Also, there is absolutely no reason to loop through all folders - use Application.Session.GetDefaultFolder(olFolderSentMail) - it will work even if the "Sent Items" folder name is localized. Secondly, do you really need to process all items in the folder?

Check if the PR_INTERNET_MESSAGE_ID (DASL name schemas.microsoft.com/mapi/proptag/0x1035001F) property is set.



来源:https://stackoverflow.com/questions/14556829/how-to-get-message-id-or-header-in-sent-items-folder-in-outlook-2007-in-vba

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!