Getting info from selected mail item in Outlook 2010

10,570

Solution 1

The ActiveInspector() is the window that opens when the user double-clicks a mail item in the Explorer window. If the user is just viewing MailItems in the reading pane - you won't have an active inspector window (hence the NullReferenceException).

You are probably looking for the Explorer.Selection to get access to the currently selected MailItems.

 Outlook.Selection selection = this.Application.ActiveExplorer().Selection;

Solution 2

Globals.ThisAddIn.Application to get the Application object. That's probably your null reference, there is no Application object on "this" within the ribbon class.

Share:
10,570
andflow
Author by

andflow

Updated on June 04, 2022

Comments

  • andflow
    andflow almost 2 years

    I want to write an add-in for Outlook 2010. The idea is - user selects one mail item in folder, then presses the button on ribbon which starts the add-in. Add-in gets information from selected item, process it and displays result. I run in to problems when trying to get the Inspector of selected item. I tried:

    Outlook.Inspector Point = this.Application.ActiveInspector().CurrentItem as Outlook.Inspector;
    Outlook.MailItem mailItem = Point.CurrentItem as Outlook.MailItem;
    

    Of course this doesn't check if current item is actually an mail item but that's for later. My problem is, when i try running the program i get NullReferenceException. The only working examples of this I found on web was with event handling. But I want to start add-in on button press..

    I am trying to make this in .NET 3.5 not 4