'C# -EWS - Setting custom properties on Exchange service for Outlook email

I would like to save a boolean property on an email. If user clicked on my addin button, i'd like to mark selected email as treated. Using UserProperties of MailItem class will update it on local folder.

  1. Not on the Exchange server, right?
  2. If i'd like to prevent a second operation execution on same mail, let's say after re-installing Outlook, or using same Outlook profile in another machine, what should I do to avoid this?

Thank you very much



Solution 1:[1]

Any property you read or set using the Outlook Object Model, you can access using EWS. Outlook user properties values are stored as regular named MAPI properties; they are stored on the items on the server, not just locally.

You just need to request the extended property when reading the data. See https://docs.microsoft.com/en-us/previous-versions/office/developer/exchange-server-2010/dd633697(v%3Dexchg.80).

You can see existing properties and their values in OutlookSpy (I am its author) - click IMessage button to see the properties on the MAPI level (you can also see DASL property names that you will need to use in EWS). Or click EWS | GetItem to see the data on the EWS level.

Solution 2:[2]

Not on the Exchange server, right?

It depends on the Exchange connection mode used in the profile - cached or not. In case of non-cached mode, your changes are propagated to the server-side. If you are in the cached mode your changes are saved to the local store until you/Outlook synchronize your changes with the server. You can start such operations programmatically, see How To: Perform Send/Receive in Outlook programmatically for more information.

If i'd like to prevent a second operation execution on same mail, let's say after re-installing Outlook, or using same Outlook profile in another machine, what should I do to avoid this?

I'd suggest creating a standalone web service where you may pass a generated item's ID (for example, hash) and check whether you need to add a user property to prevent duplication. Or just use EWS for checking whether a property is already set or not.

Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source
Solution 1
Solution 2 Eugene Astafiev