Programatically opened mail item not triggering events

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

Programatically opened mail item not triggering events
 
Jamie Reid


Guest


I'm creating an outlook add-in that is doing some processing on the body and attachments of an email when opened. In order to not have a save dialog pop up when closing the email, on the open event I'm creating a copy of the mailitem, displaying the copied mailitem in a new window and then canceling the original. This is for the most part working exactly as I want it to, all of the processing is done on the duplicated email and displayed correctly and there is no save dialog when closing.

The issue I'm having is that closing the duplicated email does not trigger the close event. Is there a way that I can set a new close event handler to the duplicated email so ensure that it is triggered?
Posted 08 May, 2015 16:14:50 Top
Andrei Smolin


Add-in Express team


Posts: 18829
Joined: 2006-05-11
Hello Jamie,

First off, you can use a new Outlook Item (not Items!) events class. Also, you can manually connect to the Close event of the MailItem object using += (C#) or AddHandler (VB.NET). Still, I would spend more time to understand why the event isn't raised. Can it be that your code releases the Item or disconnects from its events before it is closed?


Andrei Smolin
Add-in Express Team Leader
Posted 11 May, 2015 04:42:43 Top
Jamie Reid


Guest


Thank Andrei,

I was able to get the close event to work using

OutlookItemEvents itemEvents = new OutlookItemEvents(this.Module);
itemEvents.ConnectTo(mail, true);


I'm not sure why the events were disconnected from the new email but I have a feeling is is a result of the new mail item being created within the open event of a different mail item and then cancelling the open event.
Posted 11 May, 2015 10:02:18 Top
Andrei Smolin


Add-in Express team


Posts: 18829
Joined: 2006-05-11
Jamie Reid writes:
I have a feeling is is a result of the new mail item being created within the open event of a different mail item and then cancelling the open event.


To disconnect, you call OutlookItemEvents.RemoveConnection(). You can check if your code issues such a call.


Andrei Smolin
Add-in Express Team Leader
Posted 11 May, 2015 10:37:50 Top