AdxOutlookEvents.ItemSend and Extended MAPI Properties

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

AdxOutlookEvents.ItemSend and Extended MAPI Properties
 
Philipp Sigrist




Posts: 4
Joined: 2020-09-07
Greetings,

### intro ###

first let me Thank you for your Product and your Service.
One of the first project in my IT-related career I pursued back then was a one man show from the development side, in which the Outlook-Plugin component was based on AddinExpress.
And I remember the forums a very useful place in the process of solving some strange technical issues when working with Office-Customizations, MAPI, etc. in C# .NET.

These days I now work as freelancer, and Iíve got the project to modernize this first project I mentioned above.

So iíve got the old sources, changed the .NET Version from .NET 3.5 to 4.7.2,
updated AddinExpress and Redemption, and did some unrelated Ribbon based modernization.

And as it sometimes happens ... the first version intended to be tested in production on a few workplaces which developed some issues with the last version from 2014 passed a bit of user-testing and got rolled-out.

But it turned out that there is a problem in one part of the code left untouched but behaving differently.

Iíve done my best to solve this on my own and rule out some possible sources of errors. But now Iím kind of stuck.

### technical description ###

AdxOutlookEvents.ItemSend is used to ask the user what should happen later with the mail.

The Outlook.MailItem received by the event is saved and used to create a Redemption.RDOMail for our mail wrapper class.

Based on the user decision and config some modification could happen to the mail here, but more important we use Redemption to save the user decision as UserProperty to do dependent stuff later.
So after saving the changes and stop the process here, the mail is in the draft folder, containing the user decision as extended MAPI property.

In the old installation, based on .NET 3.5, Outlook 2010 and AddinExpress 7.3.4061.2005
the user decision is found as extended MAPI property in the item in the sent item folder.

But in the updated version, which is based on AddinExpress 9.4.4644.0 and tested on Outlook 2010 and 2013 yet, the extended MAPI property containing the user decision is not found in the sent item, although it was there in the item in draft before stepping out of AdxOutlookEvents.ItemSend

Now after rechecking our code and ruled out problems with redemption (the old installation runs flawlessly with the old and the new version of Redemption),
Iím wondering if you guys from AddinExpress have some ideas of what could be the issue here.


kind regards
Philipp Sigrist
Posted 07 Sep, 2020 02:41:06 Top
Dmitry Kostochko


Add-in Express team


Posts: 2865
Joined: 2004-04-05
Hi Philipp,

First off, thank you for your kind words!

As for the issue... The ItemSend event of the ADXOutlookEvents component is quite a static thing, I have just compared the source code of version 7.X with the latest sources and did not find anything suspicious. I may assume that something was changed in your updated code and suggest testing it in this way:
1) Perform all user actions that add the extended MAPI property to an email but do not send the email, leave it in the Drafts folder.
2) Restart Outlook and check if the property exists in the draft email. You can use VBA or Outlook Spy for this.
3) Send the email manually and check if the property exists in the Sent Items folder.

Looking forward to your test results.
Posted 07 Sep, 2020 07:06:54 Top
Philipp Sigrist




Posts: 4
Joined: 2020-09-07
Hi Dmitry,

thank you.

I've set a breakpoint right at the end of the ItemSend event.

If I kill the process at the end of the ItemSend event, OutlookSpy shows me the extended properties in the draft mail. after manual sending the mail without the addin enabled the extended properties are also in the mail in sent items.

However, if i jump with F11 over the end of the ItemSend event, im in the beginning of AdxOutlookEvents_InspectorClose. If i kill the process there, the mail is already sended. If i look now in the sended mail, the extended properties are missing.
Posted 07 Sep, 2020 08:07:01 Top
Dmitry Kostochko


Add-in Express team


Posts: 2865
Joined: 2004-04-05
Hi Philipp,

Do you save the mail item in the AdxOutlookEvents_InspectorClose event handler? It seems that a closing inspector overrides the changes you made in the ItemSend event handler. It is just my assumption, please check this.

Also, have you tried to work with the UserProperties collection via the Outlook Object Model, not redemption?
Posted 07 Sep, 2020 11:34:43 Top
Philipp Sigrist




Posts: 4
Joined: 2020-09-07
Hi Dmitry,

thanks.
I've created a new Project which only uses the ItemSend event, which leeds to the same described behavior


private void adxOutlookAppEvents1_ItemSend(object sender, ADXOlItemSendEventArgs e)
        {
            try
            {
                Outlook.MailItem itm = null;
                if(e.Item is Outlook.MailItem)
                {
                    // 1. save outlook item & get EntryID
                    String entryID = ""; 
                    itm = (Outlook.MailItem) e.Item;
                    itm.Save();
                    entryID = itm.EntryID;

                    Marshal.ReleaseComObject(itm);

                    // 2. Because of archetectural needs and the need to use our mail object outside of outlook too, we ended up using redemption in our mail-wrapper, doing this:
                    var rdmSession = new Redemption.RDOSession();
                    rdmSession.MAPIOBJECT = AddinModule.CurrentInstance.OutlookApp.Session.MAPIOBJECT;

                    var rMail = rdmSession.GetMessageFromID(entryID);
                    var prop = rMail.UserProperties.Add("someUserProp", Redemption.rdoUserPropertyType.olText);
                    prop.Value = "0";
                    rMail.Save();

                    Marshal.ReleaseComObject(rMail);
                }
            }catch(Exception ex)
            {
                MessageBox.Show(ex.ToString());
            }
        }


No AdxOutlookEvents_InspectorClose event involved here, but same behavior.

Using the Outlook Object Model to add the UserProperty works.

But i would really prefer to understand why this is not working anymore and fixing it, because changing to the Outlook Object Model would introduce a lot of work and potential error sources for me.
Posted 07 Sep, 2020 16:03:39 Top
Dmitry Kostochko


Add-in Express team


Posts: 2865
Joined: 2004-04-05
Hi Philipp,

Thank you for the code sample. I have just reproduced the issue on my side and after some testing found one interesting thing. Please have a look at the code below (sorry, it is not 100% completed, the inspector window shall be closed):

private void adxOutlookAppEvents1_ItemSend(object sender, ADXOlItemSendEventArgs e)
{
    try
    {
        if (e.Item is Outlook._MailItem)
        {
            // 1. save outlook item & get EntryID 
            Outlook._MailItem itm = e.Item as Outlook._MailItem;
            itm.Save();
            string entryID = itm.EntryID;

            // Marshal.ReleaseComObject(itm); // DO NOT RELEASE, it is the Add-in Express property

            // 1.1 cancel sending
            e.Cancel = true;
            // TODO: close inspector

            // 2. Because of archetectural needs and the need to use our mail object outside of outlook too, we ended up using redemption in our mail-wrapper, doing this: 
            var rdmSession = RedemptionLoader.new_RDOSession();
            Outlook._NameSpace session = this.OutlookApp.Session;
            rdmSession.MAPIOBJECT = session.MAPIOBJECT;
            Marshal.ReleaseComObject(session);

            var rMail = rdmSession.GetMessageFromID(entryID);
            var prop = rMail.UserProperties.Add("someUserProp", Redemption.rdoUserPropertyType.olText);
            prop.Value = "0";
            rMail.Save();

            // 2.1 send updated email
            rMail.Send();

            Marshal.ReleaseComObject(rMail);
        }
    }
    catch (Exception ex)
    {
        MessageBox.Show(ex.ToString());
    }
}


If I stop sending the Outlook email (e.Item) and send the RDO email, the property exists. I don't have any reasonable explanation of this behavior but it seems that we have 2 different email objects.

To make sure there is no bug in the Add-in Express code, I am going to test this code in a pure VSTO add-in. This will take some time, I will inform you about the results as soon as possible.
Posted 08 Sep, 2020 06:26:03 Top
Dmitry Kostochko


Add-in Express team


Posts: 2865
Joined: 2004-04-05
Hi Philipp,

I have tested your code with a pure VSTO add-in and can confirm that the issue exists there as well. Please have a look at the piece of code below:

private void ThisAddIn_Startup(object sender, System.EventArgs e)
{
    Application.ItemSend += Application_ItemSend;
}

private void Application_ItemSend(object Item, ref bool Cancel)
{
    try
    {
        if (Item is Outlook._MailItem)
        {
            // 1. save outlook item & get EntryID 
            Outlook._MailItem itm = Item as Outlook._MailItem;
            itm.Save();
            string entryID = itm.EntryID;

            // 2. Because of archetectural needs and the need to use our mail object outside of outlook too, we ended up using redemption in our mail-wrapper, doing this: 
            var rdmSession = RedemptionLoader.new_RDOSession();
            rdmSession.MAPIOBJECT = this.Application.Session.MAPIOBJECT;

            var rMail = rdmSession.GetMessageFromID(entryID);
            var prop = rMail.UserProperties.Add("someUserProp", Redemption.rdoUserPropertyType.olText);
            prop.Value = "0";
            rMail.Save();

            Marshal.ReleaseComObject(rMail);
        }
    }
    catch (Exception ex)
    {
        MessageBox.Show(ex.ToString());
    }
}


If you need the complete source code of my test add-in, please contact me via email, you can find our support email address in the readme.txt file located in the Add-in Express installation folder.
Posted 08 Sep, 2020 09:43:58 Top
Philipp Sigrist




Posts: 4
Joined: 2020-09-07
Hi Dmitry,

thank you for looking into the issue.
As it turned out, it wasn't related to AddinExpress.
The Author of Redemption pointed me to the fact that i was using the wrong function for this scenario.
So the using of rdmSession.GetRDOObjectFromOutlookObject instead of rdmSession.GetMessageFromID solved the issue.
Posted 14 Sep, 2020 02:00:18 Top
Andrei Smolin


Add-in Express team


Posts: 17361
Joined: 2006-05-11
Hello Philipp,


Thank you for letting us know.

Regards from Belarus (GMT+3),

Andrei Smolin
Add-in Express Team Leader
Posted 14 Sep, 2020 02:05:09 Top