ItemSend Event Outlook for Windows Addin not firing

Viewed 595

I am having trouble getting the ItemSend event to work for an Outlook addin I'm working on. I'm totally stumped as to what I've setup wrong.

The relevant parts of the manifest are as follows:

    <VersionOverrides xmlns="http://schemas.microsoft.com/office/mailappversionoverrides" xsi:type="VersionOverridesV1_0">
        <VersionOverrides xmlns="http://schemas.microsoft.com/office/mailappversionoverrides/1.1" xsi:type="VersionOverridesV1_1">
          <Requirements>
            <bt:Sets DefaultMinVersion="1.3">
              <bt:Set Name="Mailbox"/>
            </bt:Sets>
          </Requirements>
          <Hosts>
            <Host xsi:type="MailHost">
              <DesktopFormFactor>
                <FunctionFile resid="OnSend.Url"/>
                ...
                <!-- OnSend extension point -->
                <ExtensionPoint xsi:type="Events">
                  <Event Type="ItemSend" FunctionExecution="synchronous" FunctionName="onSendHandler"/>
                </ExtensionPoint>
              </DesktopFormFactor>
            </Host>
          </Hosts>
        <Resources>
          ...
        <bt:Urls>
            ...
            <bt:Url id="OnSend.Url" DefaultValue="https://localhost:3000/onsend.html"/>
            ...
          </bt:Urls>
          ...
        </Resources>
        </VersionOverrides>
      </VersionOverrides>

I then have onsend.js paired up with onsend.html, my onsend.js is very simple:

var mailboxItem

Office.initialize = function(reason){
    mailboxItem = Office.context.mailbox.item
}

function onSendHandler(event){
    Office.context.mailbox.item.notificationMessages.addAsync("progress",{
        type: "progressIndicator",
        message: "Processing"
    })
    setTimeout(()=> event.completed(), 5000)
}

My Outlook version is as follows:

enter image description here

When I send an e-mail, there is a brief moment where a notification appears that says my add-in is working but no progress bar appears as in the code, and the 5 second timeout does not fire. It also fails to send if the server is not running, so I feel like it's picking up the manifest but just not running the function.

Any help would be so greatly appreciated!

EDIT: blank manifest and accompanying js code

<?xml version="1.0" encoding="UTF-8" standalone="yes"?>
<OfficeApp xmlns="http://schemas.microsoft.com/office/appforoffice/1.1" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:bt="http://schemas.microsoft.com/office/officeappbasictypes/1.0" xmlns:mailappor="http://schemas.microsoft.com/office/mailappversionoverrides/1.0" xsi:type="MailApp">
  <Id>d49cc7b2-77eb-4c98-978d-0ce6e3745e4d</Id>
  <Version>1.0.0.0</Version>
  <ProviderName>Contoso</ProviderName>
  <DefaultLocale>en-US</DefaultLocale>
  <DisplayName DefaultValue="onsendtest"/>
  <Description DefaultValue="A template to get started."/>
  <IconUrl DefaultValue="https://localhost:3000/assets/icon-32.png"/>
  <HighResolutionIconUrl DefaultValue="https://localhost:3000/assets/icon-80.png"/>
  <SupportUrl DefaultValue="https://www.contoso.com/help"/>
  <AppDomains>
    <AppDomain>contoso.com</AppDomain>
  </AppDomains>
  <Hosts>
    <Host Name="Mailbox"/>
  </Hosts>
  <Requirements>
    <Sets>
      <Set Name="Mailbox" MinVersion="1.1"/>
    </Sets>
  </Requirements>
  <FormSettings>
    <Form xsi:type="ItemEdit">
      <DesktopSettings>
        <SourceLocation DefaultValue="https://localhost:3000/taskpane.html"/>
      </DesktopSettings>
    </Form>
  </FormSettings>
  <Permissions>ReadWriteItem</Permissions>
  <Rule xsi:type="RuleCollection" Mode="Or">
    <Rule xsi:type="ItemIs" ItemType="Message" FormType="Edit"/>
  </Rule>
  <DisableEntityHighlighting>false</DisableEntityHighlighting>
  
  <VersionOverrides xmlns="http://schemas.microsoft.com/office/mailappversionoverrides" xsi:type="VersionOverridesV1_0">
    <VersionOverrides xmlns="http://schemas.microsoft.com/office/mailappversionoverrides/1.1" xsi:type="VersionOverridesV1_1">
      <Requirements>
        <bt:Sets DefaultMinVersion="1.8">
          <bt:Set Name="Mailbox"/>
        </bt:Sets>
      </Requirements>
      <Hosts>
        <Host xsi:type="MailHost">
          <DesktopFormFactor>
            <FunctionFile resid="Commands.Url"/>
            <ExtensionPoint xsi:type="Events">
                <Event Type="ItemSend" FunctionExecution="synchronous" FunctionName="action" />
            </ExtensionPoint>
            <ExtensionPoint xsi:type="MessageReadCommandSurface">
              <OfficeTab id="TabDefault">
                <Group id="msgReadGroup">
                  <Label resid="GroupLabel"/>
                  <Control xsi:type="Button" id="msgReadOpenPaneButton">
                    <Label resid="TaskpaneButton.Label"/>
                    <Supertip>
                      <Title resid="TaskpaneButton.Label"/>
                      <Description resid="TaskpaneButton.Tooltip"/>
                    </Supertip>
                    <Icon>
                      <bt:Image size="16" resid="Icon.16x16"/>
                      <bt:Image size="32" resid="Icon.32x32"/>
                      <bt:Image size="80" resid="Icon.80x80"/>
                    </Icon>
                    <Action xsi:type="ShowTaskpane">
                      <SourceLocation resid="Taskpane.Url"/>
                    </Action>
                  </Control>
                  <Control xsi:type="Button" id="ActionButton">
                    <Label resid="ActionButton.Label"/>
                    <Supertip>
                      <Title resid="ActionButton.Label"/>
                      <Description resid="ActionButton.Tooltip"/>
                    </Supertip>
                    <Icon>
                      <bt:Image size="16" resid="Icon.16x16"/>
                      <bt:Image size="32" resid="Icon.32x32"/>
                      <bt:Image size="80" resid="Icon.80x80"/>
                    </Icon>
                    <Action xsi:type="ExecuteFunction">
                      <FunctionName>action</FunctionName>
                    </Action>
                  </Control>
                </Group>
              </OfficeTab>
            </ExtensionPoint>
          </DesktopFormFactor>
        </Host>
      </Hosts>
      <Resources>
        <bt:Images>
          <bt:Image id="Icon.16x16" DefaultValue="https://localhost:3000/assets/icon-16.png"/>
          <bt:Image id="Icon.32x32" DefaultValue="https://localhost:3000/assets/icon-32.png"/>
          <bt:Image id="Icon.80x80" DefaultValue="https://localhost:3000/assets/icon-80.png"/>
        </bt:Images>
        <bt:Urls>
          <bt:Url id="Commands.Url" DefaultValue="https://localhost:3000/commands.html"/>
          <bt:Url id="Taskpane.Url" DefaultValue="https://localhost:3000/taskpane.html"/>
        </bt:Urls>
        <bt:ShortStrings>
          <bt:String id="GroupLabel" DefaultValue="Contoso Add-in"/>
          <bt:String id="TaskpaneButton.Label" DefaultValue="Show Taskpane"/>
          <bt:String id="ActionButton.Label" DefaultValue="Perform an action"/>
        </bt:ShortStrings>
        <bt:LongStrings>
          <bt:String id="TaskpaneButton.Tooltip" DefaultValue="Opens a pane displaying all available properties."/>
          <bt:String id="ActionButton.Tooltip" DefaultValue="Perform an action when clicked."/>
        </bt:LongStrings>
      </Resources>
    </VersionOverrides>
  </VersionOverrides>
</OfficeApp>

Office.initialize = function(reason){

}

function action(event) {
  const message = {
    type: Office.MailboxEnums.ItemNotificationMessageType.InformationalMessage,
    message: "Performed action.",
    icon: "Icon.80x80",
    persistent: true
  };

  // Show a notification message
  Office.context.mailbox.item.notificationMessages.replaceAsync("action", message);

  // Be sure to indicate when the add-in command function is complete
  event.completed({allowEvent: true})
}

EDIT 2: Getting this error when trying to run on the web: Outlook on the Web Error

1 Answers

To anyone that comes across this, using the stock yo office webpack config doesn't seem to work with the ItemSend event. Not sure why - it could be something to do with how HtmlWebpackPlugin converts the file, I haven't dug too deep. What I ended up doing to get the ItemSend event to fire was add the following to the plugins section of the webpack config:

plugins:[
    ...
    new CopyWebpackPlugin({
      patterns:[
        {
          from: '[path to event handler code file].js',
          to: './'
        }
      ]
    })
 ]

You will also need to reference this file in your static ItemSend html file. If you try to pass the javascript along with the HtmlWebpackPlugin bundles, the function will not fire. Copying in the raw file itself was the only way I could get it to work. Hopefully this helps anyone who ran into the same problem as me.

Related