Add a custom action as a response to a mail item

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

Example

Note

The following code example is an excerpt from Programming Applications for Microsoft Office Outlook 2007.

You can create custom actions programmatically to appear on the ribbon in the Actions group on the Message tab in an email 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 MailItemis saved.

Note

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

If you use Visual Studio to test this code example, you must first add a reference to the Microsoft Outlook 15.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();
    }

See also