Eugene Astafiev

How To: Customize the context ribbon of Outlook 2013 inline response

After Microsoft published the Preview version of Office 2013 we started to receive lots of questions regarding built-in ribbon control IDs. Developers wanted to support the new Microsoft Office version but couldn’t find the required information on MSDN.

At the moment of writing, Microsoft is yet to publish the list of new control identifiers for Office 2013 (see for Office 2007 and Office 2010). And developers continue to express concerns on MSDN (Still no new Schema File for Office 2013) and our forum (How to customize Inline Response Message Ribbon).

So, in my today’s article I would like to draw your attention to the new Inline Response feature introduced in Outlook 2013 and explain how you can add your own controls to its context tabs.

On the right side of the Outlook window you can see the reading pane which has the Reply, Reply All and Forward buttons at the top:

Outlook 2013 Reading Pane

When you click any of these buttons you will see the following changes (for example, I clicked the Reply button in my tests):

Replying to the messages directly in the Outlook 2013 inline response window

The reading pane is transformed to the editable state allowing users to reply to e-mails inline rather than opening a new Inspector window. This feature of Outlook 2013 is called inline response.

How to add custom ribbon controls to Outlook 2013 inline response context

As a developer, you might have noticed the new context tab – MESSAGE – that appears at the top of the Outlook window when the inline response feature is active. How can we add our custom controls to this contextual tab? To demonstrate this, I have developed a sample add-in for Outlook 2013, which adds a ribbon group to the Message tab, see Our context group in the screenshot:

A custom ribbon group and a tab for Outlook 2013 inline response

The solution is very simple indeed – you need to use the Context.TabComposeTools value for the Context property and the TabMessage value for the IdMso property of the ADXRibbonTab component! As you probably guessed already I used Add-in Express for Office and .net.

The plug-in also adds a separate contextual tab to the Compose tools context:

A new contextual tab added to the Compose tools group

In that case you just need to set the Outlook.TabComposeTools value to the Context property of your ADXRibbonTab component.

How to get an inline response item in Outlook 2013

For handling inline replies Outlook 2013 introduces a new event which notifies developers when the inline response is activated – the InlineResponse event. I have also found the InlineResponseClose event on MSDN. It looks like it should be added to Outlook 2013 later ;-) To leverage the extended capabilities from the Word Object Model, developers can use the ActiveInlineResponseWordEditor property, which returns a Word Document of the active inline response.

Also, Outlook 2013 introduces a new property for the Explorer class – ActiveInlineResponse. It allows getting an item which is listed in the Outlook 2013 reading pane in case the inline response is active. Please remember, if you develop an add-in which supports earlier Outlook versions as well using version neutral interops, you need to use the late binding technology to access the ActiveInlineResponse property. The DisplayInlineResponseSubject method used in this sample add-in accepts an instance of the Outlook Application class and displays a message box with the subject of the inline response item.

    C# code example:
private void DisplayInlineResponseSubject(Outlook._Application OutlookApp)
{
    Outlook.Explorer explorer = null;
    Outlook.MailItem response = null;
    try
    {
        explorer = OutlookApp.ActiveExplorer();
        // response = explorer.ActiveInlineResponse;
        response = explorer.GetType().InvokeMember("ActiveInlineResponse",
                             System.Reflection.BindingFlags.GetProperty | 
                             System.Reflection.BindingFlags.Instance |
                             System.Reflection.BindingFlags.Public, 
                             null, explorer, null) as Outlook.MailItem;
        if (response != null)
            System.Windows.Forms.MessageBox.Show(response.Subject, 
                            "The inline response e-mail's subject");
    }
    catch (Exception ex)
    {
        System.Windows.Forms.MessageBox.Show(ex.Message, 
               "An exception was thrown in the code...");
    }
    finally
    {
        if (response != null) Marshal.ReleaseComObject(response);
        if (explorer != null) Marshal.ReleaseComObject(explorer);
    }
}
    VB.NET code example:
Private Sub DisplayInlineResponseSubject(OutlookApp As Outlook._Application)
    Dim explorer As Outlook.Explorer = Nothing
    Dim response As Outlook.MailItem = Nothing
    Try
        explorer = OutlookApp.ActiveExplorer()
        ' response = explorer.ActiveInlineResponse
        response = explorer.GetType().InvokeMember("ActiveInlineResponse", _
                               System.Reflection.BindingFlags.GetProperty Or _ 
                               System.Reflection.BindingFlags.Instance Or _
                               System.Reflection.BindingFlags.Public, _
                               Nothing, explorer, Nothing)
       If Not IsNothing(response) Then
           System.Windows.Forms.MessageBox.Show(response.Subject, _ 
                             "The inline response e-mail's subject")
       End If
   Catch ex As Exception
       System.Windows.Forms.MessageBox.Show(ex.Message, _
                "An exception was thrown in the code...")
   Finally
       If Not IsNothing(response) Then Marshal.ReleaseComObject(response)
       If Not IsNothing(explorer) Then Marshal.ReleaseComObject(explorer)
    End Try
End Sub

See you next week and have a great weekend! :-)

Available downloads:

These sample Outlook 2013 add-ins were developed using Add-in Express for Office and .net:
C# Outlook addin
VB.NET Outlook addin

11 Comments

  • http://0.gravatar.com/avatar/0e823e79ec0f2da0a9050e87ff3e683c?s=32&d=http%3A%2F%2F0.gravatar.com%2Favatar%2Fad516503a11cd5ca435acc9bb6523536%3Fs%3D32&r=G Dmitry says:

    Thank you for this useful article! My aim is to add a BCC by using a similar code.
    However, I found out that ‘response’ does not have a “BCC” property. How do I get to this property?..

  • http://0.gravatar.com/avatar/ab4ec2858cfdf1e44dadf8c50fae314d?s=32&d=http%3A%2F%2F0.gravatar.com%2Favatar%2Fad516503a11cd5ca435acc9bb6523536%3Fs%3D32&r=G Dmitry Kostochko (Add-in Express Team) says:

    Hi Dmitry,

    You can try to use the Item parameter of the InlineResponse event. Type cast it to MailItem and use its properties and methods.

  • http://0.gravatar.com/avatar/458766449b575b3bcb0f044303b14066?s=32&d=http%3A%2F%2F0.gravatar.com%2Favatar%2Fad516503a11cd5ca435acc9bb6523536%3Fs%3D32&r=G joey says:

    Great How To!
    Is it possible to have the example for “Add-in Express for VCL”
    I’m trying to find the equivalence of “explorer.GetType().InvokeMember(“ActiveInlineResponse” in delphi/pascal.
    Thanks!

  • http://0.gravatar.com/avatar/ab4ec2858cfdf1e44dadf8c50fae314d?s=32&d=http%3A%2F%2F0.gravatar.com%2Favatar%2Fad516503a11cd5ca435acc9bb6523536%3Fs%3D32&r=G Dmitry Kostochko (Add-in Express Team) says:

    Hi Joey,

    You can use late binding in Delphi by casting an interface variable to the OleVariant type:
    var
    IResponse: IDispatch;
    begin
    // …
    IResponse := OleVariant(explorer).ActiveInlineResponse;
    // …

  • http://1.gravatar.com/avatar/96e3fe7766b6b864540653275ef1b27b?s=32&d=http%3A%2F%2F1.gravatar.com%2Favatar%2Fad516503a11cd5ca435acc9bb6523536%3Fs%3D32&r=G Fabrice says:

    Just for information, it seems Microsoft finally published the list of buttons identifier: http://www.microsoft.com/en-us/download/details.aspx?id=36798

  • http://0.gravatar.com/avatar/ec56458b8087fe52cef869e2045ba0e5?s=32&d=http%3A%2F%2F0.gravatar.com%2Favatar%2Fad516503a11cd5ca435acc9bb6523536%3Fs%3D32&r=G Katharina says:

    Hi,
    any ideas why this “The solution is very simple indeed – you need to use the Context.TabComposeTools value for the Context property and the TabMessage value for the IdMso property of the ADXRibbonTab component!” does NOT work? Neither Group nor button is added after changing the values of These two properties of a newly created empty ADXRibbonTab.
    Would be thankful for any advice, because I do feel that this could turn out not to be “very simple”.
    Thanks in advance
    Katharina

  • Hello Katharina,

    You can use the links at the end of the text to download a sample project. Find the InitializeComponent() method of the add-in module and compare the settings with your project. This method is generated to reflect the components and their settings that you use in the add-in module designer. Hope this helps.

  • http://1.gravatar.com/avatar/7bc03fb43e3087d52daa0e4b5eb74808?s=32&d=http%3A%2F%2F1.gravatar.com%2Favatar%2Fad516503a11cd5ca435acc9bb6523536%3Fs%3D32&r=G Eugene Astafiev (Add-in Express Team) says:

    Hello Katharina,

    Please use the following Ribbon XML markup for VSTO based add-ins:
    <customUI xmlns=”http://schemas.microsoft.com/office/2006/01/customui” onLoad=”RibbonLoaded” loadImage=”LoadImages”>
    <ribbon startFromScratch=”false”>
    <contextualTabs>
    <tabSet idMso=”TabComposeTools”>
    <tab getVisible=”getVisible” idMso=”TabMessage”>
    <group getLabel=”getLabel” getVisible=”getVisible” id=”MYRibbonGroup”>
    <button getDescription=”getDescription” getEnabled=”getEnabled” getImage=”getImage” getLabel=”getLabel” getShowImage=”getShowImage” getShowLabel=”getShowLabel” getSize=”getSize” getVisible=”getVisible” id=”MyRibbonButton” onAction=”onAction” />
    </group>
    </tab>
    </tabSet>
    </contextualTabs>
    </ribbon>
    </customUI>

    Don’t forget to add the required callback to your code behind files.

  • http://0.gravatar.com/avatar/ec56458b8087fe52cef869e2045ba0e5?s=32&d=http%3A%2F%2F0.gravatar.com%2Favatar%2Fad516503a11cd5ca435acc9bb6523536%3Fs%3D32&r=G Katharina says:

    I give up.
    And curse at those who made it THAT much more difficult to add a button to a contextual ribbon than to an ordinary ribbon. Have to accept it, but cannot understand. Thanks for your attempts.

  • http://0.gravatar.com/avatar/ab4ec2858cfdf1e44dadf8c50fae314d?s=32&d=http%3A%2F%2F0.gravatar.com%2Favatar%2Fad516503a11cd5ca435acc9bb6523536%3Fs%3D32&r=G Dmitry Kostochko (Add-in Express Team) says:

    Katharina,

    I am really sorry that you have had continued difficulties with this.

    Please send your project to our support email address, I will try to find the cause of the problem and fix it. You can find our support email address in the readme.txt file located in the Add-in Express installation folder.

Post a comment

Have any questions? Ask us right now!