0

I am creating a Microsoft Outlook add-in (Visual Studio 2012, C#, COM add-in, no VSTO, Outlook 2010/2013/2016), where 1) users must be able to compose and read various fields that must be mapped to/from MIME headers when messages leave/enter Microsoft Exchange, and 2) the fields must be available as native Outlook fields to be used e.g. as columns in Outlook views, in search expressions, etc.

To obtain 1), the add-in reads and writes (MAPI) fields in the PS_INTERNET_HEADERS namespace. When the add-in is first loaded, it creates a dummy hidden message that ensures that Exchange is forced to do the mapping between MIME headers and MAPI properties for incoming messages (addressing the problem described in Named Properties, X-Headers, and You). That works fine.

To obtain 2), I have created an old-fashioned Outlook Form Configuration File (Creating a Form Configuration File) with entries like:

[Property.MMHSFoo]
Type=31
NmidPropset={00020386-0000-0000-C000-000000000046}
NmidString=MMHS-Foo
DisplayName=Foo

Then I use Outlook Redemption to register the form when the add-in loads. Now users can use field Foo as other Outlook fields.

Now, my problem is that when I use the Outlook form designer to create a form region, if I try to add field Foo, I get an error saying ‘The operation failed’. If I change the NmidPropset value from PS_INTERNET_HEADERS (00020386-0000-0000-C000-000000000046) to PS_PUBLIC_STRINGS (00020329-0000-0000-C000-000000000046), I can add field Foo, but then 1) does not work.

Thus my question is: how can I add fields from namespace PS_INTERNET_HEADERS to an Outlook form region such that both requirement 1) and 2) are fulfilled?

1 Answers1

0

Firstly, for (1), you don't need to create any messages - just call GetIDsFromNames(...MAPI_CREATE) on any store object (IMsgStore, IMAPIFolder, IMessage, etc.).

For (2), I don't think the form will work with anything but PS_PUBLIC_STRINGS. Why not create a task pane and populate its contents explicitly in your code?

Dmitry Streblechenko
  • 62,942
  • 4
  • 53
  • 78
  • I actually created a custom task pane for just that reason. One thing that I did not mention was that I also wanted my properties to appear when messages are printed. Properties on a form get printed, but properties from PS_INTERNET_HEADERS do not get printed. Any advice? – Lars Iversen Mar 09 '16 at 12:02
  • The properties need to be in the UserProperties collection to be printable. – Dmitry Streblechenko Mar 09 '16 at 14:17
  • In the context of an inspector window, I use the UserProperties collection to set a UserProperty. If I then choose to print the message, the change to that UserProperty is not included in the print. But if I close the message and then reopen it, then the change is included. The code is similiar to 'mailItem.UserProperties.Add("Foo", Outlook.OlUserPropertyType.olText, false)'. On the other hand, if I use OutlookSpy to make the same change, the change is reflected immediately, i.e. the print includes the change without having to reopen the message. What does OutlookSpy do differently? – Lars Iversen Mar 12 '16 at 09:11
  • Disregard the last comment, my mistake, I was adding the property, but not settings its value. – Lars Iversen Mar 12 '16 at 16:32
  • The GetIDsFromNames works fine for an Outlook profile _not_ running in Cached Exchange Mode, but it does not work for a profile running in Cached Exchange Mode. How can I force the promotion in that case? – Lars Iversen Sep 15 '16 at 09:00
  • Are you sure it does not work after the changes (property mapping) in the cached store and synchronized with the online store? You can also try to open an object (such as IMAPIFolder or IMessage) to be opened in the online mode using the MAPI_NO_CACHE flag. – Dmitry Streblechenko Sep 15 '16 at 13:33
  • Perhaps it will eventually synchronize, but 10 minutes or so was not enough. I switched to open a folder (the inbox) with the MAPI_NO_CACHE flag, that works immediately, thanks! – Lars Iversen Sep 15 '16 at 19:54
  • Great! If this answers the question, please mark the reply as the answer. Thanks! – Dmitry Streblechenko Sep 16 '16 at 06:16