0

Working in Windows 11 Pro 64 and MS Office LTSC Pro Plus 2021.

I'm building a spreadsheet of properties of a selection of e-mails. I understand that the way to do this is to use an Outlook table generated by a command like oEmailFolder.GetTable(sFilter) and then add to the table columns for the properties that I want using a command like oOutlookTable.Columns.Add("property").

This question is a follow-up to my previous one on adding a table column for Sender and some other properties. I understand now that Sender and Attachments are objects, so adding them to the table is unsupported if they are referenced by name. Trying to do so yields "Run-time error '-2147024809 (80070057)': The property "Attachments" does not support this operation." But adding them is supposed to be "supported if property is referenced by its namespace". So I'm trying to do that.

Microsoft's documentation on Referencing Properties by Namespace has a section on Outlook Namespaces, which says that Outlook item-level properties can be referenced by:

urn:schemas-microsoft-com:office:outlook#name

So I tried to add Attachments using

oColumns.Add ("urn:schemas-microsoft-com:office:outlook#Attachments")

Doing that brought up the error:

Run-time error '-2147024809 (80070057)': The property "urn:schemas-microsoft-com:office:outlook#Attachments" is unknown.

That page also mentions another namespace that seemed promising, urn:schemas:mailheader, so I tried:

oColumns.Add ("urn:schemas:mailheader#Attachments")

From that, I got:

Run-time error '-2147024809 (80070057)': The property "urn:schemas:mailheader#Attachments" does not support this operation.

which is the same error I was getting when I tried to add it referencing it by name.

What is the correct syntax to reference this object property for use in the oColumns.Add() method?

NewSites
  • 1,402
  • 2
  • 11
  • 26

1 Answers1

2

It is the same issue - you can only retrieve scalar values (strings, int, boolean, etc.) from a table. Recipients and Attachments are stored separately as subobjects. You can search on recipient or attachment properties in Extended MAPI, but not in Outlook Object Model. Sender is similar, even though it does not really exist in Extended MAPI - you have sender name, email address, entry id, etc., but not the sender object. You can always retrieve the sender entry id and open it as an AddressEntry object using Namespace.GetAddressEntryFromID.

Dmitry Streblechenko
  • 62,942
  • 4
  • 53
  • 78
  • Okay, I really only want the scalar components. For example, I want to include `Attachments.Count` in the data so I know if there is an attachment or not. Is there a way for me to add that scalar to the table? – NewSites May 17 '23 at 17:53
  • 2
    No, `Attachments.Count` is a scalar property on the `Attachments` collection, which you cannot touch in a table. What you **can** do, is retrieve `PR_HASATTACH` property (DASL name `"http://schemas.microsoft.com/mapi/proptag/0x0E1B000B"`) - it will be true for the messages with attachments, hidden or not. You can then open the messages by the entry id (which you can request from a table) and explicitly check the `MailItem.Attachments` collection. – Dmitry Streblechenko May 17 '23 at 18:46
  • 1
    Implemented successfully. Thank you. Is there a place to get a list of these namespace IDs (if I can call them that) of all the scalars in each of the MailItem properties that are objects? – NewSites May 17 '23 at 20:38
  • You can look at messages with MFCMAPI (https://github.com/stephenegriffin/mfcmapi - can be a bit overwhelming) or OutlookSpy (https://www.dimastr.com/outspy - I am its author, click IMessage button to see all properties and their DASL names) – Dmitry Streblechenko May 17 '23 at 22:09