如何在“已发送邮件"中获取Message-Id或标头VBA中Outlook-2007中的文件夹

问题描述:

这是此主要问题

我可以使用以下功能循环获取其他文件夹的Internet标头

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.

PR_TRANSPORT_MESSAGE_HEADERS仅适用于从POP3帐户收到的邮件.永远不会在传出消息上设置它. 另外,绝对没有理由遍历所有文件夹-使用Application.Session.GetDefaultFolder(olFolderSentMail)-即使已发送邮件"文件夹名称已本地化,它也将起作用. 其次,您是否真的需要处理文件夹中的所有项目?

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?

检查是否设置了PR_INTERNET_MESSAGE_ID(DASL名称为schemas.microsoft.com/mapi/proptag/0x1035001F)属性.

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