Edit

Prepend or append content to a message or appointment body on send

The prepend-on-send and append-on-send features enable your Outlook add-in to insert content to the body of a message or appointment when the mail item is sent. These features further boost your users' productivity and security by enabling them to:

  • Add sensitivity and classification labels to their messages and appointments for easier item identification and organization.
  • Insert disclaimers for legal purposes.
  • Add standardized headers for marketing and communication purposes.

In this walkthrough, you'll develop an add-in that prepends a header and appends a disclaimer when a message is sent.

Note

Support for the append-on-send feature was introduced in requirement set 1.9, while support for the prepend-on-send feature was introduced in requirement set 1.13. See clients and platforms that support these requirement sets.

Set up your environment

Complete the Outlook quick start which creates an add-in project with the Yeoman generator for Office Add-ins.

Configure the manifest

To configure the manifest, select the tab for the type of manifest you'll use.

Note

Add-ins that use the unified manifest for Microsoft 365 aren't supported in Outlook on Mac. We're working hard to provide that support. In the meantime, if your customer base includes users on the Mac, you need to create a version of your add-in that uses the add-in only manifest and support them both. For more information, see Support for add-ins with the unified manifest for Microsoft 365.

The following shows how to configure your unified manifest to enable the prepend-on-send and append-on-send features.

  1. Open the manifest.json file.

  2. Add the following object to the "extensions.runtimes" array. Note the following about this code.

    • The "minVersion" of the Mailbox requirement set is set to "1.13", so the add-in can't be installed on platforms and Office versions where this feature isn't supported.
    • The "id" of the runtime is set to the descriptive name, "function_command_runtime".
    • The "code.page" property is set to the URL of the UI-less HTML file that will load the function command.
    • The "lifetime" property is set to "short", which means that the runtime starts up when the function command button is selected and shuts down when the function completes. (In certain rare cases, the runtime shuts down before the handler completes. See Runtimes in Office Add-ins.)
    • There are actions specified to run the "prependHeaderOnSend" and "appendDisclaimerOnSend" functions. You'll create these functions in a later step.
    {
        "requirements": {
            "capabilities": [
                {
                    "name": "Mailbox",
                    "minVersion": "1.13"
                }
            ],
            "formFactors": [
                "desktop"
            ]
        },
        "id": "function_command_runtime",
        "type": "general",
        "code": {
            "page": "https://localhost:3000/commands.html"
        },
        "lifetime": "short",
        "actions": [
            {
                "id": "prependHeaderOnSend",
                "type": "executeFunction"
            },
            {
                "id": "appendDisclaimerOnSend",
                "type": "executeFunction"
            }
        ]
    }
    
  3. Add the following object to the "extensions.ribbons" array. Note the following about this code.

    • The "mailCompose" value is added to the "contexts" array to surface the prepend-on-send and append-on-send buttons in a compose window.
    • The "controls" objects create and configure the buttons for the prepend-on-send and append-on-send functions. The "actionId" property of each object must reflect the same value specified in the applicable "actions.id" property of the "extensions.runtimes" object.
    {
        "contexts": [
            "mailCompose"
        ],
        "tabs": [
            {
                "builtInTabId": "TabDefault",
                "groups": [
                    {
                        "id": "msgComposeGroup",
                        "label": "Contoso Add-in",
                        "icons": [
                            {
                                "size": 16,
                                "url": "https://localhost:3000/assets/icon-16.png"
                            },
                            {
                                "size": 32,
                                "url": "https://localhost:3000/assets/icon-32.png"
                            },
                            {
                                "size": 80,
                                "url": "https://localhost:3000/assets/icon-80.png"
                            }
                        ],
                        "controls": [
                            {
                                "id": "PrependButton",
                                "type": "button",
                                "label": "Prepend header",
                                "icons": [
                                    {
                                        "size": 16,
                                        "url": "https://localhost:3000/assets/icon-16.png"
                                    },
                                    {
                                        "size": 32,
                                        "url": "https://localhost:3000/assets/icon-32.png"
                                    },
                                    {
                                        "size": 80,
                                        "url": "https://localhost:3000/assets/icon-80.png"
                                    }
                                ],
                                "supertip": {
                                    "title": "Prepend header on send",
                                    "description": "Prepend the Contoso header on send."
                                },
                                "actionId": "prependHeaderOnSend"
                            },
                            {
                                "id": "AppendButton",
                                "type": "button",
                                "label": "Add disclaimer",
                                "icons": [
                                    {
                                        "size": 16,
                                        "url": "https://localhost:3000/assets/icon-16.png"
                                    },
                                    {
                                        "size": 32,
                                        "url": "https://localhost:3000/assets/icon-32.png"
                                    },
                                    {
                                        "size": 80,
                                        "url": "https://localhost:3000/assets/icon-80.png"
                                    }
                                ],
                                "supertip": {
                                    "title": "Append disclaimer on send",
                                    "description": "Append the Contoso disclaimer on send."
                                },
                                "actionId": "appendDisclaimerOnSend"
                            }
                        ]
                    }
                ]
            }
        ]
    }
    
  4. In the "authorization.permissions.resourceSpecific" array, add the following object. Be sure it's separated from other objects in the array with a comma.

    {
      "name": "Mailbox.AppendOnSend.User",
      "type": "Delegated"
    }
    
  5. Save your changes.