outlook - Uniquely identify Mailitem -


i need store model every used mailitem. i've written following method

    private readonly static dictionary<string, permitcustompaneviewmodel> viewmodellookup = new dictionary<string, permitcustompaneviewmodel>();      public static permitcustompaneviewmodel createorget(mailitem c)     {         if (c.entryid == null)             c.save();         if (!viewmodellookup.containskey(c.entryid))         {             var vm = new permitcustompaneviewmodel(c);             c.unload += () => viewmodellookup.remove(c.entryid);             viewmodellookup.add(c.entryid, vm);         }         return viewmodellookup[c.entryid];     } 

when model exists, , return it. if not created, create , remove entry after mailitem unloaded.

however have observed mailitem object not vailid time untill unload called. in order reliable identify mailitem used entryid. problem works if item saved.

so save item if no entryid found. automaticly saves item under draft.

is there way distingush mailitem's not saved in way can used in dictionary<,>.

new created items don't have entryid property set. id assigned store provider must save it. if need identify new mailitem object may consider adding user property item using userproperties.add method reates new user property in userproperties collection. example:

sub adduserproperty()   dim myitem outlook.contactitem   dim myuserproperty outlook.userproperty    set myitem = application.createitem(olcontactitem)   set myuserproperty = myitem.userproperties _   .add("lastdatespokenwith", oldatetime)   myitem.display  end sub 

be aware, entry id changes when item moved store, example, inbox microsoft exchange server public folder, or 1 personal folders (.pst) file .pst file. solutions should not depend on entryid property unique unless items not moved. works fine long message staying in parent folder or may changed if outlook item moved different folder (depends on store provider).

you may consider using message id message mime header (pr_internet_message_id , pr_transport_message_headers). not set on newly created items. these properties available on message received smtp server or through smtp connector.


Comments

Popular posts from this blog

php - Vagrant up error - Uncaught Reflection Exception: Class DOMDocument does not exist -

vue.js - Create hooks for automated testing -

Add new key value to json node in java -