项目发送事件的 Node.js Outlook 加载项事件处理程序?

问题描述 投票:0回答:0

我是创建 Outlook 加载项 的新手,我在我的项目中使用 Node.js,我不知道我的代码使用 Event Handler for Item Send Event 有什么问题,但它不起作用所有人,任何人都可以帮助我完成我的项目......

清单.xml

<?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>7a2edb11-abd6-4efb-840f-c382b1f27922</Id>
<Version>1.0.0.0</Version>
<ProviderName>Contoso</ProviderName>
<DefaultLocale>en-US</DefaultLocale>
<DisplayName DefaultValue="QB Add-In"/>
<Description DefaultValue="A template to get started."/>
<IconUrl DefaultValue="https://localhost:3000/assets/icon-64.png"/>
<HighResolutionIconUrl DefaultValue="https://localhost:3000/assets/icon-128.png"/>
<SupportUrl DefaultValue="https://www.contoso.com/help"/>
<AppDomains>
  <AppDomain>https://www.contoso.com</AppDomain>
</AppDomains>
<Hosts>
  <Host Name="Mailbox"/>
</Hosts>
<Requirements>
  <Sets>
    <Set Name="Mailbox" MinVersion="1.1"/>
  </Sets>
</Requirements>
<FormSettings>
  <Form xsi:type="ItemRead">
    <DesktopSettings>
      <SourceLocation DefaultValue="https://localhost:3000/taskpane.html"/>
      <RequestedHeight>250</RequestedHeight>
    </DesktopSettings>
  </Form>
</FormSettings>
<Permissions>ReadWriteItem</Permissions>
<Rule xsi:type="RuleCollection" Mode="Or">
  <Rule xsi:type="ItemIs" ItemType="Message" FormType="Read"/>
</Rule>
<DisableEntityHighlighting>false</DisableEntityHighlighting>
<VersionOverrides xmlns="http://schemas.microsoft.com/office/mailappversionoverrides" xsi:type="VersionOverridesV1_0">
  <Requirements>
    <bt:Sets DefaultMinVersion="1.3">
      <bt:Set Name="Mailbox"/>
    </bt:Sets>
  </Requirements>
  <Hosts>
    <Host xsi:type="MailHost">
      <DesktopFormFactor>
        <FunctionFile resid="Commands.Url"/>
        <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>

        <ExtensionPoint xsi:type="MessageComposeCommandSurface">
          <OfficeTab id="TabDefault">
            <Group id="msgComposeCmdGroup">
              <Label resid="GroupLabel"/>
              <Control xsi:type="Button" id="msgComposeInsertGist">
                <Label resid="TaskpaneButton.Label"/>
                <Supertip>
                  <Title resid="TaskpaneButton.Title"/>
                  <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>
            </Group>
          </OfficeTab>
        </ExtensionPoint>

        <ExtensionPoint xsi:type="Events">
          <Event Type="Office.EventType.ItemSend" FunctionName="onItemSend" />
        </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="TaskpaneButton.Title" 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>

taskpane.js

Office.onReady((info) => {
  if (info.host === Office.HostType.Outlook) {
    document.getElementById("sideload-msg").style.display = "none";
    document.getElementById("app-body").style.display = "flex";
    document.getElementById("run").onclick = run;

    // Add the following code to register the event handler for ItemSend event
    Office.context.mailbox.addHandlerAsync(
      Office.EventType.ItemSend,
      onItemSend
    );
  }
});

export async function run() {
  /**
   * Insert your Outlook code here
   */
}

// Add the following function to handle the ItemSend event
async function onItemSend(event) {
  // Prevent sending the email if certain condition is not met
  console.log("ItemSend event triggered.");
  event.preventDefault();
}

onItemSend 函数在按下 Send 按钮后从 Outlook 撰写新电子邮件时不起作用,我尝试向该函数添加 API 请求但它不起作用,我的代码似乎有什么问题

node.js outlook outlook-addin outlook-web-addins outlook-restapi
© www.soinside.com 2019 - 2024. All rights reserved.