none
Is there any interprocess communication in outlook? RRS feed

  • Question

  • Due to requeriments from a costumer, I need to read the subject of the email being read in the Outlook desktop app.

    Is there any way to achieve this?

    Luis

    Tuesday, August 18, 2015 4:54 PM

Answers

  • In the preview pane - track the Application.ActiveExplorer.SelectionChange event and process the selection collection.

    Email being read in an inspector - track the Application.Inspectors.NewInspector event, read the Inspector.CurrentItem property.


    Dmitry Streblechenko (MVP)
    http://www.dimastr.com/redemption
    Redemption - what the Outlook
    Object Model should have been
    Version 5.5 is now available!


    Tuesday, August 18, 2015 5:00 PM
  • Outlook Object Model is the same for the COM addins and external applications. The only differences are

    1. COM addins get a trusted (no security prompts) iinstance of the Outlook.Application object, no need to craeet a new instance

    2. Ribbons are exposed to the COM addins only (IRibbonExtensibility interface).


    Dmitry Streblechenko (MVP)
    http://www.dimastr.com/redemption
    Redemption - what the Outlook
    Object Model should have been
    Version 5.5 is now available!

    • Marked as answer by JLuis Estrada Tuesday, August 18, 2015 10:37 PM
    Tuesday, August 18, 2015 10:15 PM

All replies

  • In the preview pane - track the Application.ActiveExplorer.SelectionChange event and process the selection collection.

    Email being read in an inspector - track the Application.Inspectors.NewInspector event, read the Inspector.CurrentItem property.


    Dmitry Streblechenko (MVP)
    http://www.dimastr.com/redemption
    Redemption - what the Outlook
    Object Model should have been
    Version 5.5 is now available!


    Tuesday, August 18, 2015 5:00 PM
  • But this only apply for addins, right?

    Can I use it outside outlook, for example a WPF app?

    Tuesday, August 18, 2015 5:49 PM
  • Outlook Object Model is the same for the COM addins and external applications. The only differences are

    1. COM addins get a trusted (no security prompts) iinstance of the Outlook.Application object, no need to craeet a new instance

    2. Ribbons are exposed to the COM addins only (IRibbonExtensibility interface).


    Dmitry Streblechenko (MVP)
    http://www.dimastr.com/redemption
    Redemption - what the Outlook
    Object Model should have been
    Version 5.5 is now available!

    • Marked as answer by JLuis Estrada Tuesday, August 18, 2015 10:37 PM
    Tuesday, August 18, 2015 10:15 PM
  • I think I got this. What I did was getting the active object using Marshal, and then, I just retrieved the ActiveWindow.

    Thank you soo much for your help

    I will paste the code in case somebody needs it

     static void Main(string[] args)
            {
                var res = GetOutlookEmailSubject();
    
                System.Console.WriteLine(res);
    
                System.Console.ReadKey();
            }
    
            private static string GetOutlookEmailSubject ()
            {
                var app = (Application)System.Runtime.InteropServices.Marshal.GetActiveObject("Outlook.Application");
    
                dynamic mainWindow = app.ActiveWindow();
    
                if (mainWindow is Explorer)
                {
                    System.Console.WriteLine("Explorer");
                    Explorer exp = mainWindow as Explorer;
    
                    foreach (var item in exp.Selection)
                    {
                       return  GetSubjectFromItem(item);
                    }
                }
                else if (mainWindow is Inspector)
                {
                    System.Console.WriteLine("Inspector");
                    Inspector ins = mainWindow as Inspector;
    
                    return GetSubjectFromItem(ins.CurrentItem);
                }
    
                return null;
    
            }
    
            private static string GetSubjectFromItem(dynamic item)
            {
                if (item is MailItem)
                {
                    var mi = item as MailItem;
    
                    return mi.Subject;
                }
                else if (item is AppointmentItem)
                {
                    var ai = item as AppointmentItem;
    
                    return ai.Subject;
                }
                return null;
            }

    Tuesday, August 18, 2015 10:37 PM