A visitor wanted to export the sender address and other metadata exposed using the CFG at How to display the sender's email address in Outlook. The fields can be copied and pasted into Excel or Notepad, but can't be exported.
While simple VBA will get the sender and sender email as both are exposed in the object model, to get fields not in the object model, you need to use PropertyAccessor object.
This sample prints the properties exposed by the Extended-Properties CFG to the Debug window.
Option Explicit Public Sub ShowCreatedDate() Dim oItem As Object Dim propertyAccessor As Outlook.propertyAccessor Set oItem = Application.ActiveExplorer.Selection.Item(1) Set propertyAccessor = oItem.propertyAccessor Debug.Print "Sender Display name: " & oItem.Sender Debug.Print "Sender address: " & oItem.SenderEmailAddress Debug.Print "PR_INTERNET_MESSAGE_ID", propertyAccessor.GetProperty("http://schemas.microsoft.com/mapi/proptag/0x1035001E") Debug.Print "PR_LAST_VERB_EXECUTED", propertyAccessor.GetProperty("http://schemas.microsoft.com/mapi/proptag/0x10810003") Debug.Print "PR_LAST_VERB_EXECUTION_TIME", propertyAccessor.GetProperty("http://schemas.microsoft.com/mapi/proptag/0x10820040") Set oItem = Nothing End Sub
The full list of available properties for email is below. Calendar, Contacts, Tasks, Journal, and Notes will each have their own Properties.
' Types of Properties 'Email Message Properties "PR_MESSAGE_CLASS", propertyAccessor.GetProperty("http://schemas.microsoft.com/mapi/proptag/0x001A001E") "PR_SUBJECT", propertyAccessor.GetProperty("http://schemas.microsoft.com/mapi/proptag/0x0037001E") "PR_CLIENT_SUBMIT_TIME", propertyAccessor.GetProperty("http://schemas.microsoft.com/mapi/proptag/0x00390040") "PR_SENT_REPRESENTING_SEARCH_KEY", propertyAccessor.BinaryToString(propertyAccessor.GetProperty("http://schemas.microsoft.com/mapi/proptag/0x003B0102")) "PR_SUBJECT_PREFIX PT_STRING8", propertyAccessor.GetProperty("http://schemas.microsoft.com/mapi/proptag/0x003D001E") "PR_RECEIVED_BY_ENTRYID", propertyAccessor.BinaryToString(propertyAccessor.GetProperty("http://schemas.microsoft.com/mapi/proptag/0x003F0102")) "PR_RECEIVED_BY_NAME", propertyAccessor.GetProperty("http://schemas.microsoft.com/mapi/proptag/0x0040001E") "PR_SENT_REPRESENTING_ENTRYID", propertyAccessor.BinaryToString(propertyAccessor.GetProperty("http://schemas.microsoft.com/mapi/proptag/0x00410102")) "PR_SENT_REPRESENTING_NAME", propertyAccessor.GetProperty("http://schemas.microsoft.com/mapi/proptag/0x0042001E") "PR_REPLY_RECIPIENT_ENTRIES", propertyAccessor.BinaryToString(propertyAccessor.GetProperty("http://schemas.microsoft.com/mapi/proptag/0x004F0102")) "PR_REPLY_RECIPIENT_NAMES", propertyAccessor.GetProperty("http://schemas.microsoft.com/mapi/proptag/0x0050001E") "PR_RECEIVED_BY_SEARCH_KEY", propertyAccessor.BinaryToString(propertyAccessor.GetProperty("http://schemas.microsoft.com/mapi/proptag/0x00510102")) "PR_SENT_REPRESENTING_ADDRTYPE", propertyAccessor.GetProperty("http://schemas.microsoft.com/mapi/proptag/0x0064001E") "PR_SENT_REPRESENTING_EMAIL_ADDRESS", propertyAccessor.GetProperty("http://schemas.microsoft.com/mapi/proptag/0x0065001E") "PR_CONVERSATION_TOPIC", propertyAccessor.GetProperty("http://schemas.microsoft.com/mapi/proptag/0x0070001E") "PR_CONVERSATION_INDEX", propertyAccessor.BinaryToString(propertyAccessor.GetProperty("http://schemas.microsoft.com/mapi/proptag/0x00710102")) "PR_RECEIVED_BY_ADDRTYPE", propertyAccessor.GetProperty("http://schemas.microsoft.com/mapi/proptag/0x0075001E") "PR_RECEIVED_BY_EMAIL_ADDRESS", propertyAccessor.GetProperty("http://schemas.microsoft.com/mapi/proptag/0x0076001E") "PR_TRANSPORT_MESSAGE_HEADERS", propertyAccessor.GetProperty("http://schemas.microsoft.com/mapi/proptag/0x007D001E") "PR_SENDER_ENTRYID", propertyAccessor.BinaryToString(propertyAccessor.GetProperty("http://schemas.microsoft.com/mapi/proptag/0x0C190102")) "PR_SENDER_NAME", propertyAccessor.GetProperty("http://schemas.microsoft.com/mapi/proptag/0x0C1A001E") "PR_SENDER_SEARCH_KEY", propertyAccessor.BinaryToString(propertyAccessor.GetProperty("http://schemas.microsoft.com/mapi/proptag/0x0C1D0102")) "PR_SENDER_ADDRTYPE", propertyAccessor.GetProperty("http://schemas.microsoft.com/mapi/proptag/0x0C1E001E") "PR_SENDER_EMAIL_ADDRESS", propertyAccessor.GetProperty("http://schemas.microsoft.com/mapi/proptag/0x0C1F001E") "PR_DISPLAY_BCC", propertyAccessor.GetProperty("http://schemas.microsoft.com/mapi/proptag/0x0E02001E") "PR_DISPLAY_CC", propertyAccessor.GetProperty("http://schemas.microsoft.com/mapi/proptag/0x0E03001E") "PR_DISPLAY_TO", propertyAccessor.GetProperty("http://schemas.microsoft.com/mapi/proptag/0x0E04001E") "PR_MESSAGE_DELIVERY_TIME", propertyAccessor.GetProperty("http://schemas.microsoft.com/mapi/proptag/0x0E060040") "PR_MESSAGE_FLAGS", propertyAccessor.GetProperty("http://schemas.microsoft.com/mapi/proptag/0x0E070003") "PR_MESSAGE_SIZE", propertyAccessor.GetProperty("http://schemas.microsoft.com/mapi/proptag/0x0E080003") "PR_PARENT_ENTRYID", propertyAccessor.BinaryToString(propertyAccessor.GetProperty("http://schemas.microsoft.com/mapi/proptag/0x0E090102")) "PR_MESSAGE_RECIPIENTS", propertyAccessor.GetProperty("http://schemas.microsoft.com/mapi/proptag/0x0E12000D") "PR_MESSAGE_ATTACHMENTS", propertyAccessor.GetProperty("http://schemas.microsoft.com/mapi/proptag/0x0E13000D") "PR_HASATTACH", propertyAccessor.GetProperty("http://schemas.microsoft.com/mapi/proptag/0x0E1B000B") "PR_NORMALIZED_SUBJECT", propertyAccessor.GetProperty("http://schemas.microsoft.com/mapi/proptag/0x0E1D001E") "PR_RTF_IN_SYNC", propertyAccessor.GetProperty("http://schemas.microsoft.com/mapi/proptag/0x0E1F000B") "PR_PRIMARY_SEND_ACCT", propertyAccessor.GetProperty("http://schemas.microsoft.com/mapi/proptag/0x0E28001E") "PR_NEXT_SEND_ACCT", propertyAccessor.GetProperty("http://schemas.microsoft.com/mapi/proptag/0x0E29001E") "PR_ACCESS", propertyAccessor.GetProperty("http://schemas.microsoft.com/mapi/proptag/0x0FF40003") "PR_ACCESS_LEVEL", propertyAccessor.GetProperty("http://schemas.microsoft.com/mapi/proptag/0x0FF70003") "PR_MAPPING_SIGNATURE", propertyAccessor.BinaryToString(propertyAccessor.GetProperty("http://schemas.microsoft.com/mapi/proptag/0x0FF80102")) "PR_RECORD_KEY", propertyAccessor.BinaryToString(propertyAccessor.GetProperty("http://schemas.microsoft.com/mapi/proptag/0x0FF90102")) "PR_STORE_RECORD_KEY", propertyAccessor.BinaryToString(propertyAccessor.GetProperty("http://schemas.microsoft.com/mapi/proptag/0x0FFA0102")) "PR_STORE_ENTRYID", propertyAccessor.BinaryToString(propertyAccessor.GetProperty("http://schemas.microsoft.com/mapi/proptag/0x0FFB0102")) "PR_OBJECT_TYPE", propertyAccessor.GetProperty("http://schemas.microsoft.com/mapi/proptag/0x0FFE0003") "PR_ENTRYID", propertyAccessor.BinaryToString(propertyAccessor.GetProperty("http://schemas.microsoft.com/mapi/proptag/0x0FFF0102")) "PR_BODY", propertyAccessor.GetProperty("http://schemas.microsoft.com/mapi/proptag/0x1000001E") "PR_RTF_COMPRESSED", propertyAccessor.BinaryToString(propertyAccessor.GetProperty("http://schemas.microsoft.com/mapi/proptag/0x10090102")) "PR_HTML", propertyAccessor.BinaryToString(propertyAccessor.GetProperty("http://schemas.microsoft.com/mapi/proptag/0x10130102")) "PR_INTERNET_MESSAGE_ID", propertyAccessor.GetProperty("http://schemas.microsoft.com/mapi/proptag/0x1035001E") "PR_LIST_UNSUBSCRIBE", propertyAccessor.GetProperty("http://schemas.microsoft.com/mapi/proptag/0x1045001E") "PR_INTERNET_REFERENCES_W", propertyAccessor.GetProperty("http://schemas.microsoft.com/mapi/proptag/0x1039001F") "PR_IN_REPLY_TO_ID_W", propertyAccessor.GetProperty("http://schemas.microsoft.com/mapi/proptag/0x1042001F") "N/A", propertyAccessor.GetProperty("http://schemas.microsoft.com/mapi/proptag/0x1046001E") "PR_CREATION_TIME", propertyAccessor.GetProperty("http://schemas.microsoft.com/mapi/proptag/0x30070040") "PR_LAST_MODIFICATION_TIME", propertyAccessor.GetProperty("http://schemas.microsoft.com/mapi/proptag/0x30080040") "PR_SEARCH_KEY", propertyAccessor.BinaryToString(propertyAccessor.GetProperty("http://schemas.microsoft.com/mapi/proptag/0x300B0102")) "PR_STORE_SUPPORT_MASK", propertyAccessor.GetProperty("http://schemas.microsoft.com/mapi/proptag/0x340D0003") "N/A", propertyAccessor.GetProperty("http://schemas.microsoft.com/mapi/proptag/0x340F0003") "PR_MDB_PROVIDER", propertyAccessor.BinaryToString(propertyAccessor.GetProperty("http://schemas.microsoft.com/mapi/proptag/0x34140102")) "PR_INTERNET_CPID", propertyAccessor.GetProperty("http://schemas.microsoft.com/mapi/proptag/0x3FDE0003") "SideEffects", propertyAccessor.GetProperty("http://schemas.microsoft.com/mapi/proptag/0x80050003") "InetAcctID", propertyAccessor.GetProperty("http://schemas.microsoft.com/mapi/proptag/0x802A001E") "InetAcctName", propertyAccessor.GetProperty("http://schemas.microsoft.com/mapi/proptag/0x804F001E") "RemoteEID", propertyAccessor.BinaryToString(propertyAccessor.GetProperty("http://schemas.microsoft.com/mapi/proptag/0x80660102")) "x-rcpt-to", propertyAccessor.GetProperty("http://schemas.microsoft.com/mapi/proptag/0x80AD001E")
More Information
PropertyAccessor object (Outlook) (Microsoft Docs)
Diane Poremsky, great post.I'm not able to use PR_RECEIVED_BY_EMAIL_ADDRESSas a filter.
I can use "urn:schemas:httpmail:displayto" with Application.AdvancedSearch(scopeFolder, filter)
but it only finds emails where "To" field displays exactly the email, not the AccountName related to it.
Example
An email message for "john.doe@outlook.com" where the filed To is "John Doe" woulb not be found.
Only the emails with To = "john.doe@outlook.com".
Also tried as search parameter "urn:schemas:httpmail:to", but no success.
Hi Diane,
thank you for sharing all this with us!
I'm struggling with setting the "In-Reply-To"-Property. I cannot find it in the basic object model, and I cannot find the namespace or correct addressing for using described propertyAccessor.SetProperty .
Why do I need it? I use .msg - Files saved outside of Outlook, and a objMailItem.Reply fails with unclear err.description I cannot solve.
Thanks for any clue!
.ReplyRecipients ?
MailItem.ReplyRecipients property (Outlook) | Microsoft Docs
Thanks for your quick comment! Well, no: "In-Reply-To" is something like a topic, not an email-address. I need to return the received message_ID. Example:
From: Nick Oetjen <me@domain.com>
To: Nick Oetjen <aliasn@example.de>
Subject: AW: Mail 4 you
Thread-Index: AQHW0vq2um/AHOnEGaWqEwv9lCoKn8yuMg
Date: Fri, 18 Dec 2020 13:22:32 +0100
Message-ID: <7188bd80aae14bedb8eb7de3415eeeec Slipstick.com>
References: <OAmgnPj0AmmAV5eDb8cvJzqBx.3482950.123>
In-Reply-To: <3579.222.your-message-id.xyz_and_meoryouorso>
Ah.
That would be
Debug.Print "PR_IN_REPLY_TO_ID_W", propertyAccessor.GetProperty("http://schemas.microsoft.com/mapi/proptag/0x1042001F")
This should also contain the value - but might reference more than one message.
Debug.Print "PR_INTERNET_REFERENCES_W", propertyAccessor.GetProperty("http://schemas.microsoft.com/mapi/proptag/0x1039001F")
Thanks again! With this, I was able to read and write the value for both a MailItem made by .reply and createFromTemplate().
Unfortunately, the property will not be included by Outlook when sending in the latter case, which was what I would want. At least, I couldn't get it to work, I've given up.
message id is set by the server.
Hi Diane,
Sorry a bit long to repost the whole question here but any idea why I cant get sender address : https://stackoverflow.com/questions/65079067/returning-outlook-sender-address-from-vba-in-excel
Did you try
Debug.Print Item.SenderEmailAddress
That should work.
Diane Poremsky
Hi Diane,
Can you help me with putting mark as replied miniicon manually to a message on IMAP Protocol.
I put the replied icon properly but not synchronize to the IMAP Server. Do you have Idea on how to propagate to IMAP Server the new flags.
Sub MarkAsReplied()
On Error Resume Next
For Each Item In ActiveExplorer.Selection
Item.PropertyAccessor.SetProperty "http://schemas.microsoft.com/mapi/proptag/0x10800003", 261
Item.Save
Next
End Sub
Thanks
The server uses more than just the icon in Outlook to show it was replied to - depending on the imap server, it may not show the indicator in web mail.
Yeah this is my problem, I can put it on outlook but I cannot sync it to the IMAP Server and ofcourse not visible to web mail. Do you have and Idea some codes to help and I will try to figure it out.
Hi Diane,
Are there known problems with the PropertyAccesor GetProperty method in Outlook 2007?
I'm actually trying to target an AppointmentItem PR_RTF_COMPRESSED property, but even with short (well under 8K) mail messages accessing straightforward MailItem properties such as PR_BODY fail with (e.g.) 'The property "http://schemas.microsoft.com/mapi/proptag/0x1000001E" does not support this operation.'
Thanks.
The only limitation I'm aware of is the 8K one. Propertyaccessors were a lottle buggy in 2007 though.
Hi Diane,
I've been trying to get the PR_INTERNET_MESSAGE_ID to use in a VBA solution, so your code above was perfect!
Thank you
I have a problem that is driving me nuts.
I would think this should be relatively easy.
I am trying to use MFCMapi to find the property IDs for some custom fields for a macro that will pull data from the GAL.
My company has a couple custom fields in each users GAL entry.
So when you look at someone's Outlook properties you see fields like..
First name, last name, initials, display name, alias, etc
And then there is a number of custom fields.
I have 2 company's I work for.
When I use MFCMapi on one GAL I can see all the property fields easily.
But on the GAL with the custom fields I can't see any of the custom fields and those are the ones I need to read.
For example one field has a letter S for staff or a C for contractor.
Why can't I see these fields and how do I export them?
I must be missing some basic concept, but looking at the MFCMAPI page you reference, I see the format of the value for property accessor but I can't get to a list of the actual property ID to use. Can you offer any hints on how to use the MFCMAPI documentation to compile a list such as the one you provided for email properties?
Open the data file in mfcmapi then the contacts folder then double click on one of the contacts - the property names are listed along with the type. Do the same for other items.