Cédric Boivin
Cédric Boivin

Reputation: 11361

Detecting Modal MailItem Creation in Outlook from Windows Context Menu via VSTO Add-in

I'm developing a VSTO Add-in for Outlook using C#. In a scenario where a user selects "Send to -> Mail recipient" from the right-click context menu in Windows Explorer, Outlook is invoked, and a new MailItem opens in a modal window.

My objective is to identify within the add-in when the MailItem is created from this specific action, as opposed to other ways of creating a MailItem. This is important because the behavior of my add-in depends on the origin of the MailItem creation.

Is there a way to determine programmatically in the C# VSTO add-in if a MailItem is opened in a modal window as a result of the "Send to -> Mail recipient" action? If so, how can I implement this detection?

I understand that the Outlook Inspector window does not directly expose a property to check for modality. Are there any indirect methods or properties that could reliably indicate the modal state of a MailItem or its creation context?

Upvotes: 0

Views: 61

Answers (2)

Eugene Astafiev
Eugene Astafiev

Reputation: 49455

The Outlook object model (or VSTO) doesn't provide anything for that out of the box.

If Outlook was not not running prior to using the context menu (SendTo) you can check out whether any Explorer window exists (Explorers.Count) and visible. Typically in such scenarios you deal only with an inspector window opened.

Also under scenario described you may not get some events, so keeping the sequence of events allows you to distinguish between the regular usage and the SendTo one.

Upvotes: 0

Dmitry Streblechenko
Dmitry Streblechenko

Reputation: 66286

The best I can think of is to take advantage of the fact that Inspectors.NewInspector event does not fire for messages opened through Simple MAPI even though the Inspectors collection (Count etc.) lists these inspectors: keep track of Inspectors.NewInspector and Inspector.Close events to keep your own tally of the inspectors count. If you are off, you can assume the inspector was opened through Simple MAPI.

Upvotes: 1

Related Questions