How to get the identifier or title of a message in the Sent Items folder in Outlook 2007 in VBA

This is a question in question

I can loop to 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 without working in the Sent Items folder, does anyone have experience or a link for this?

FAIL 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 this is not possible, I can BCC myself in a letter.

+2
vba outlook outlook-2007
source share
1 answer

PR_TRANSPORT_MESSAGE_HEADERS is only available for messages received from the POP3 account. It is not installed in outgoing messages. In addition, there is absolutely no reason to scroll through all folders - use Application.Session.GetDefaultFolder (olFolderSentMail) - it will work even if the name of the Sent Items folder is localized. Secondly, do you really need to handle all items in the folder?

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

+3
source share

All Articles