Outlook Add-in + Sequence of Events..

S

Sanjay

I an trying to get a sense of the sequence of events that are fired
while creating and sending a new mail item. I am using Outlook 2003
SP2 + VSTO.

I have an Add-In that has the following events wired up.
Inspector_NewInspector
MailItem_Open
MailItem_Send
MailItem_Close
Inspector_CloseInspector

Here is the scenerio that confuses me. When I create a new mail, add
the recipients, subject, message body and then close the inspector.
Outlook fires the MailItem_Close and then asks if the user would like
to save the changes. Now if you hit cancel here, the inspector remains
open but the inspector_Close event gets triggered.


I have to place the cleanup code somewhere and now I'm not sure where
the correct location would be.

Any help will be appreciated.

Thanks.
 
S

Sanjay

Sorry.. I provided some incorrect information.. Let me try again..

the the above events wired up, If is set the bool cancel to true in
MailItem_Send, MailItem_Close is skipped and Inspector_Close is fired.
Where as when I close the message window, MailItem_Close gets fired and
then there is a popup box displayed asking if I want to save the
message before closing.

Now my issues is that I display custom UI elements in the inspector
window and need to place the cleanup code somewhere. This cleanup code
would include unwiring of events.

Can't use Inspector_Close because it gets called event if the bool
cancel is set to true in MailItem_Close

Can't use MailItem_Close because it gets called before the popup is
displayed asking the user if they want to save the edits for later as
draft and if the user hits cancel, the inspector is still available.

Hope this makes sense.

Sanjay
 
K

Ken Slovak - [MVP - Outlook]

A bug was introduced in the hotfix that upped the Outlook 2003 SP version to
11.8010.6568. If you cancel a Send using code you get a "false"
Inspector.Close event. If you then close the Inspector in the UI or using
code you get the "true" .Close event.

This doesn't happen in other versions of Outlook or other builds of Outlook
2003. There you do not get an Inspector.Close event unless the Inspector is
really closing. However, the order in which Inspector.Close and Item.Close
will fire does vary depending on whether the item was sent or just closed.

A workaround I use is to set a timer object in the Send event handler if I'm
canceling the send. I set the timer for 500 ms which gives WordMail a chance
to repaginate the email, which is does if running when an item is sent or
closed. I also set a class level flag to indicate that a send was canceled.

When the timer fires I can then close the Inspector if I want or take any
other action I want. In the meantime the original "false" Inspector.Close
event will have fired. There I check the flag value and if True I just exit
..Close. If False I continue with my shutdown code.

The solution works with all the Outlook versions I've tested it on.
 
S

Sanjay

Ken --
Thanks for the quick reply.. I was getting a little frustrated.. I
ended up storing the cancel value in the wrapper for mail item and then
check that value in inspector close before doing the cleanup. Seems to
be working now. But discovered something else... When opening email
messages from outbox, the first time MailItem_Open event is fired, but
close it and try opening it again and it will not fire the
MailItem_Open... Is this a bug too?
 
S

Sanjay

One more thing.. you have to use the word mail editor to get the above
described behavior...
 
K

Ken Slovak - [MVP - Outlook]

It sounds like the item isn't being closed if you don't get another Open
event. I haven't seen that here in either the Outlook or Word editors.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top