1
votes

I'm trying to create an add-in for Outlook 2007/2010 to modify recipients of newly created email messages. Everything works fine if the user creates a new email message inside Outlook (I'm using the Inspectors.NewInspector event). But if the user uses another application (MS Word or Adobe Acrobat for example) to try to email an attachment, the NewInspector event isn't fired when the compose email window is displayed. Is there a straightforward approach to catching an event that is raised in a situation like this?

I've tried using the Application.ItemLoad event, but I can't access any methods or properties after I successfully cast it to an Outlook.MailItem (I get an error stating System.Runtime.InteropServices.COMException: The item’s properties and methods cannot be used inside this event procedure). I'm using C# in Visual Studio 2010.

1

1 Answers

0
votes

If the Outlook.exe process is not running then the NewInspector won't fire since ThisAddIn_Startup is not called except when the user opens up Outlook directly.

Since Outlook is not already running when the external application opens the new Inspector window - you would have to manually call ThisAddIn_Startup yourself or attach any custom events that need to fire when the Inspector ribbon is loaded. The best place to do this is by handling CreateRibbonExtensibilityObject or RequestService methods.

protected override object RequestService(Guid serviceGuid)
{
    if (serviceGuid == typeof(Office.IRibbonExtensibility).GUID)
       this.ThisAddIn_Startup(this, null);

    return base.RequestService(serviceGuid);
}

The only caveat with this is that you need to support method re-entry with ThisAddIn_Startup since the Ribbon and Outlook can both call the startup routine now. You will need to safely administer a lock to ensure you don't keep calling your Init (ThisAddIn_Startup) routine more than once.