'c# outlook addin - store data locally

Whenever an email is sent, I want someaction to be performed(we active this action by clicking some button that appears in the ribbon in the compose email window). I think this action need to be performed from sent items.

So, I want to create a table or a simple list that stores the ids(or something unique) while sending an email. And then whenever an email appears in sent folder, I will check if it is in the list or table that we created previously.

So,

  1. How to create, add data to those tables?

  2. Is this a good way to perform action on the sent items ?

  3. Is there any unique and common element(like some id) between compose email 'mailitem' and sent emails 'mailitem' ?

Thanks.



Solution 1:[1]

  1. What tables are you talking about?

  2. It is up to you when to perform an action. I don't see enough information in your post to suggest something else. If you want to get a valuable feedback I'd recommend describing your final goal in depth. However, you may also consider handling the ItemSend event of the Application class.

  3. Outlook uses the EntryID property value (string) to identify items. Here is what MSDN states for the entry IDs:

A MAPI store provider assigns a unique ID string when an item is created in its store. Therefore, the EntryID property is not set for an Outlook item until it is saved or sent. The Entry ID changes when an item is moved into another store, for example, from your Inbox to a Microsoft Exchange Server public folder, or from one Personal Folders (.pst) file to another .pst file. Solutions should not depend on the EntryID property to be unique unless items will not be moved.

But you are free to add your own IDs. You can use user properties to store them. See the corresponding property (UserProperties) of Outlook items for more information.

Solution 2:[2]

You can add a user property (MailItem.UserPropertiers.Add) when a message is composed, and then look for a message with that property in the Sent Items folder. In general, you cannot use the EntryID property since it changes when a message is moved from one folder to another (PST provider is the only exception)..

You can store your list/table as a user property on a hidden message in any folder of your choosing, e.g. the Inbox. See MAPIFolder.GetStorage on MSDN. You can see existing Outlook's hidden messages in OutlookSpy (I am its author) - go to the Inbox folder, click IMAPIFolder button on the OutlookSpy toolbar, go to the "Associated Contents" tab, double click on any of the hidden messages to see it properties.

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 Eugene Astafiev
Solution 2 Dmitry Streblechenko