Custom data disappeared from message

Add-in Express™ Support Service
That's what is more important than anything else

Custom data disappeared from message
 
Amiram Korach


Guest


I have read this https://www.add-in-express.com/forum/read.php?SHOWALL_1=1&a=&FID=5&TID=15024#nav_start
I have a similar problem. When I send a message, I wait it to appear in sent item with ItemAdd event of the sent folder and there I save custom properties either by UserProperties or propertyAccessor. In both ways, the custom data is deleted after few seconds. It doesn't always happen.
After it happens, I see a message on the top of the email message, saying "this is the most recent version but you made changes to another copy". If I click on this I can open another inspector with a message that has the custom data and outlook gives me the option to replace the current message with this copy and then the custom data remains.
I think it is related to the sync. When I tried to run the sync manually before I added the data, the data disappeared more quickly.
I tried to wait 5 seconds before I add the data. It doesn't help.

Thanks
Posted 08 Nov, 2018 16:56:29 Top
Andrei Smolin


Add-in Express team


Posts: 18793
Joined: 2006-05-11
Hello Amiram,

Restart Outlook: if the issue isn't reproducible than most probably, it is caused by an unreleased COM object.

Add-in Express releases all COM objects created in its code; you should release every COM object created in your code. I strongly recommend that you start with checking section Releasing COM Objects, see the PDF file in the folder {Add-in Express}\Docs on your development PC or at https://www.add-in-express.com/docs/net-office-tips.php#releasing.


Andrei Smolin
Add-in Express Team Leader
Posted 09 Nov, 2018 03:01:13 Top
Amiram Korach


Guest


Hello Andrei,
Thanks for your help. I made a tiny project that reproducing the problem. I created a new adx project (I replaced the interop dlls to version 15). I added a forms manager to show a form in compose window. I added an app events item and registered to the ItemSend event. In this event I added a property.
In order to reproduce, just sent a blank email with subject. after a few seconds, while selecting and unselecting this item in the sent folder (I'm not sure that the selection is necessary for the reproduce), I see the message "this is the most recent version but you made changes to another copy". With outlook spy I see the custom property I added only in the "another copy" that I can open if I click on the message.

The form code is pretty simple:


public partial class ADXOlForm1 : AddinExpress.OL.ADXOlForm
    {
        public const string PROPERTY_URL = "http://schemas.microsoft.com/mapi/string/{00020386-0000-0000-C000-000000000046}/";

        public ADXOlForm1()
        {
            InitializeComponent();

            MyAddin1.AddinModule.CurrentInstance.adxOutlookAppEvents1.ItemSend += AdxOutlookAppEvents1_ItemSend;
        }

        private void AdxOutlookAppEvents1_ItemSend(object sender, AddinExpress.MSO.ADXOlItemSendEventArgs e)
        {
            var mailItem = e.Item as MailItem;

            ItemsEvents_ItemAddEventHandler itemAddHandler = null;
            var sentFolder = mailItem.SaveSentMessageFolder;
            var items = sentFolder.Items;
            Marshal.ReleaseComObject(sentFolder);

            itemAddHandler = item =>
            {
                items.ItemAdd -= itemAddHandler;
                Marshal.ReleaseComObject(items);

                var sentItem = item as MailItem;

                var propertyAccessor = sentItem.PropertyAccessor;
                propertyAccessor.SetProperty(PROPERTY_URL + "x-something", "aaa");
                Marshal.ReleaseComObject(propertyAccessor);
                sentItem.Save();

                Marshal.ReleaseComObject(sentItem);
            };

            items.ItemAdd += itemAddHandler;
        }
    }
Posted 10 Nov, 2018 15:06:44 Top
Andrei Smolin


Add-in Express team


Posts: 18793
Joined: 2006-05-11
Hello Amiram,

I suggest that you you use the Items (not Item!) Events class; add it to your project using the Add New Item dialog of your project. To handle several folders, create a dictionary containing such events classes using the string value returned by MAPIFolder.FolderPath as the key of the dictionary.

In the events class, handle the ItemAdd event as you do in your code.

This allows handling all items added to such folders and avoid a potential issue which occurs if you connect to that event but the event doesn't occur (for any reason) and the COM object(s) is left unreleased.

Then make sure you have all other COM add-ins turned off.

Finally, I assume you can use an IMAP Folders (used e.g. by GMAIL) store that may have an implementation that doesn't follow some rules or it doesn't implement some things. Actually, we see issues with IMAP Folders really often. If you use an IMAP Folders, check if the issue occurs when using Exchange or PST message stores.


Andrei Smolin
Add-in Express Team Leader
Posted 12 Nov, 2018 07:14:33 Top
Amiram Korach


Guest


Hello Andrei,
Thank you for your help. My real code can't use a separate class since it needs the some data from pre-send code. Anyway, I saw that changing anything for a sent item cause a duplicate, so I changed things in my code to save the property before send, and I take the entryID and ConversationID after send, and now everything is fine. BTW, I use exchange.
Posted 12 Nov, 2018 08:39:28 Top
Andrei Smolin


Add-in Express team


Posts: 18793
Joined: 2006-05-11
Oh, it's just great!


Andrei Smolin
Add-in Express Team Leader
Posted 12 Nov, 2018 08:42:25 Top