How to: Add a Custom Action as a Response to a Mail Item

This example shows how to add custom actions as a response to an e-mail item by using the Add() method of the Actions collection.

Programming Applications for Office Outlook 2007

The following code example is an excerpt from Programming Applications for Microsoft Office Outlook 2007, from Microsoft Press (ISBN 9780735622494, copyright Microsoft Press 2007, all rights reserved).

Buy this book

Sample chapters

You can create custom actions programmatically to appear on the ribbon in the Actions group on the Message tab in an e-mail response. In the following code example, ReplyWithVoiceMail creates and adds a custom action named “Reply with Voice Mail” to the inspector command bar. ReplyWithVoiceMail first gets a _MailItem object and then creates an Action object by calling the Add method of the Actions collection that is associated with the MailItem. It then sets the Name property of the Action object to “Reply with Voice Mail”. The ReplyStyle, ResponseStyle, CopyLike, and MessageClass properties are also set. Finally, the MailItem is saved.

Note Note

You can also add custom actions at design time by using the Outlook Forms Designer.

If you use Microsoft Visual Studio to test this code example, you must first add a reference to the Microsoft Outlook 14.0 Object Library component and specify the Outlook variable when you import the Microsoft.Office.Interop.Outlook namespace. The using statement must not occur directly before the functions in the code example but must be added before the public Class declaration. The following line of code shows how to do the import and assignment in C#.

using Outlook = Microsoft.Office.Interop.Outlook;
private void ReplyWithVoiceMail()
{
    Outlook.MailItem mail = (Outlook.MailItem)Application.ActiveInspector().CurrentItem;
    Outlook.Action action = mail.Actions.Add();
    action.Name = “Reply with Voice Mail”;
    action.ReplyStyle = Outlook.OlActionReplyStyle.olUserPreference;
    action.ResponseStyle = Outlook.OlActionResponseStyle.olOpen;
    action.CopyLike = Outlook.OlActionCopyLike.olReply;
    action.MessageClass = “IPM.Post.Voice Message”;
    mail.Save();
}

Other Resources

Community Additions

ADD
Show:
© 2014 Microsoft