如何在 VBA 中的 Outlook-2007 中的“已发送邮件”文件夹中获取消息 ID 或标题

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/14556829/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-09-11 19:23:00  来源:igfitidea点击:

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

vbaoutlookoutlook-2007

提问by Larry

This is a sub-question of this mainquestion

这是这个主要问题的一个子问题

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

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

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?

但是不在“已发送邮件”文件夹上工作,有人对此有经验或参考吗?

FAILthe Property returns nothing

FAIL属性不返回任何内容

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

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

编辑如果无法实现,我可以在电子邮件中密件抄送。

回答by Dmitry Streblechenko

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 allitems in the folder?

PR_TRANSPORT_MESSAGE_HEADERS 仅适用于从 POP3 帐户接收的邮件。它永远不会在传出消息上设置。此外,绝对没有理由遍历所有文件夹 - 使用 Application.Session.GetDefaultFolder(olFolderSentMail) - 即使“已发送邮件”文件夹名称已本地化,它也可以工作。其次,你真的需要处理文件夹中的所有项目吗?

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

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