Making a Custom Group Appear in the Message Tab of a Mail Item (Norm Estabrook)

Published 09 April 08 09:49 AM

You can add a custom group to the Message tab of an Outlook mail item.  For example, here is a custom group named "MyCoolGroup" that I added to the message tab of a new message:

image

Outlook lets you open a message in the following two modes:

  • Compose (you are drafting a new message).
  • Read (you are reading a message). 

Making a custom group appear for only one of these modes is pretty easy.  Making it appear for both modes is a tad more challenging. That is because the control ID of the Message tab in read mode is different than the control ID of the Message tab in compose mode. When you design your custom group in the VSTO Ribbon designer, you can only specify one control ID. This means that when you run the project, the custom group will only appear in the Message tab of a compose window or the Message tab of a read window depending on which control ID you specify at design-time.

If you want the group to appear in both versions of the Message tab (read and compose), you have to do a bit more work. Here is how you make the group appear for both modes:

First, add a Ribbon (Visual Designer) to an Outlook 2007 add-in project.

Then, set the RibbonType property of the Ribbon to Microsoft.Outlook.Mail.Compose and Microsoft.Outlook.Mail.Read as follows:

image

On the Ribbon designer, add a group to a tab and customize the group as desired. 

On the Ribbon designer, select the tab, open the Properties window, and then set the OfficeId of the tab to TabReadMessageTabReadMessage is the control ID of the default tab that appears on the Ribbon of a mail message that is open in read mode. 

image

Ok. Now when you run the project, your custom group will appear only if you open a mail item in read mode. Now you need to add a little code to display the custom group in the Message tab of a new mail item. That is, a mail item that you open in compose mode.

To do this, create an event handler for the NewInspector event. This event is raised every time a new Outlook inspector is open. In the event handler, check the EntryID property of the mail item. If this property is null, then the item is a new message.  If that is the case, set the OfficeId property of the tab to TabNewMailMessage.   TabNewMailMessage is the control ID of the Message tab of a mail message in compose mode. 

private Outlook.Inspectors inspectors;
private void ThisAddIn_Startup(object sender, System.EventArgs e)
{
    inspectors = this.Application.Inspectors;
    inspectors.NewInspector += 
        new Microsoft.Office.Interop.Outlook.InspectorsEvents_NewInspectorEventHandler
            (Inspectors_NewInspector);
}

void Inspectors_NewInspector(Microsoft.Office.Interop.Outlook.Inspector Inspector)
{
    Outlook.MailItem tmpMailItem = (Outlook.MailItem)Inspector.CurrentItem;
    if (tmpMailItem != null)
    {
        if (tmpMailItem.EntryID == null)
            Globals.Ribbons.Ribbon1.tab1.ControlId.OfficeId = "TabNewMailMessage";
    }
}

You can read more about adding custom groups to built-in tabs in the following MSDN articles:

How to: Customize a Built-in tab

How to: Get Started Customizing the Ribbon

Ribbon Designer

Customizing a Ribbon for Outlook

Comment Notification

If you would like to receive an email when updates are made to this post, please register here

Subscribe to this post's comments using RSS

Comments

# Making A Custom Group Appear In The Message Tab A Mail Item (Norm | zekefidelio said on April 10, 2008 8:48 AM:

PingBack from http://zekefidelio.sxassociation.cn/2008/04/09/making-a-custom-group-appear-in-the-message-tab-a-mail-item-norm/

# Dor Rotman said on June 30, 2008 10:11 AM:

Very helpful information, thanks! :)

# Juan said on September 4, 2008 3:02 PM:

Hi, I need use the bold command in my Adjoining FormRegion but in the IPM.Note this command is enable except when the bodyMessage (_DocSiteControl) is select. Do you have any idea???

# Norm Estabrook said on September 15, 2008 3:31 PM:

Hi Juan,

Can you tell me a bit more about your specific scenario?  

Are you using a rich control in your form region?

Do you want the user to click the bold button in the Outlook Ribbon and have the text in the Rich control become bold?

Thank you

Norm E.

# Vales said on November 17, 2008 6:02 AM:

Nice article and helpful information but when you open the New message it show the new ribbon groups.If you open the read message first the groups will not appear when you open the new message.

# ManishK said on January 4, 2009 10:44 AM:

Nice article and very helpful. How can we achieve following..

My requirement is to add a custom panel into Outlook only in Read Mail window. This panel should not be displayed in Reply,Reply All,Forward, New email window.

I am able to create Panel and Ribbon using inspector. I have following problem to meet above requirement.

1. To display Panel and Ribbon button only during Read Widnow. I have handled Read event. This event adds panel to only Read Window

void inspectors_NewInspector(Microsoft.Office.Interop.Outlook.Inspector Inspector)

{

if (Inspector.CurrentItem is Outlook.MailItem)

{

currentInspector = Inspector;

mailEvents = Inspector.CurrentItem as Outlook.ItemEvents_10_Event;

mailEvents.Read += new Microsoft.Office.Interop.Outlook.ItemEvents_10_ReadEventHandler(mailEvents_Read);

}

}

void mailEvents_Read()

{

Wrappers.Add(currentInspector, new InspectorWrapper(currentInspector));

if (null != ribbon && null != ribbon.RibbonUI)

{

ribbon.Refresh("toggleTaskPane");

}

}

But Read event fires only once when email item is opened. If I open the same email item more than once then Read event does not fire.

2. If I use open event then I do not have way to find out window type (email window type) in open event so that I can restrict display of Panel only in Read window.

Please help me how can I achieve this.

# Norm Estabrook said on January 6, 2009 1:55 PM:

Hi ManishK,

Are you using VS2008? If so, why not use the Ribbon Designer and the new Ribbon object model?

Because I am not too familiar with the Ribbon X object model, I will focus my response on the task pane issue.

There is a great example of how to manage task panes in Outlook mail windows at the following URL - http://msdn.microsoft.com/en-us/library/bb296010.aspx.

I used that example and slightly modified the NewInspector event handler so that the task pane only appears in read-only windows.  The code seemed to work well.

Here it is:

       void Inspectors_NewInspector(Outlook.Inspector Inspector)

       {

           Outlook.MailItem tmpMailItem = (Outlook.MailItem)Inspector.CurrentItem;

           if (tmpMailItem != null)

           {

               if (tmpMailItem.EntryID != null)

               {

                   inspectorWrappersValue.Add(Inspector, new InspectorWrapper(Inspector));

                   InspectorWrapper inspectorWrapper = InspectorWrappers[Inspector];

                   CustomTaskPane taskPane = inspectorWrapper.CustomTaskPane;

                   taskPane.Visible = true;

               }

           }

       }

Also note that if you don't mind the pane appearing at the bottom of the Inspector window (instead of to the side of the Inspector window), you could also use an Outlook form region. Outlook form regions are super easy to create with VS 2008. Here is a link to some information - http://msdn.microsoft.com/en-us/library/bb157865.aspx.

The nice thing about form regions is that you simply select a few settings to control where the region appears (read window, compose window etc). Also, unlike a task pane, a form region can appear beneath a message in the preview pane.

Please let me know if this information helps.

Norm E.

# sornamuki said on April 16, 2009 5:41 AM:

in ribbon button properties...ribbon type not showing for me...how to set ribbon types

# VSTABlog said on April 17, 2009 12:40 PM:

Hello Sornamuki,

The RibbonType property is on the Ribbon not the Ribbon button.  select the Ribbon Designer and in the Properties window, you will see the RibbonType property listed.

Hope that helps

Norm E.

Leave a Comment

(required) 
(optional)
(required) 

About VSTO Team

This login represents the Visual Studio Tools for Office team. Many members of the team us this account for publishing technical blog posts.
Page view tracker