Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Outlook Event Based Activation - Not Working on Classic Outlook #5166

Closed
Buxt-Codes opened this issue Dec 7, 2024 · 5 comments
Closed

Outlook Event Based Activation - Not Working on Classic Outlook #5166

Buxt-Codes opened this issue Dec 7, 2024 · 5 comments
Assignees
Labels
Area: Outlook Issue related to Outlook add-ins

Comments

@Buxt-Codes
Copy link

Overview

I have been creating an outlook add in that is meant to warn users when sending emails to external recipients. It works as desired when used on OWA and the New Outlook Desktop however it does not work on the Classic Outlook. I have been trying to debug it and reading up on how others has tackled this issue, including trying these following methods:

devServer: { hot:false, client:false, }

static: { directory: path.join(__dirname, "dist"), publicPath: "/public", },

However, both has not worked for me and I am still facing the same issue whereby this error pops up "External Recipients Warning is unavailable and can't process your email at this time."

image

Code

Here is my manifest:

<?xml version="1.0" encoding="utf-8"?>
<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>208431dd-a771-4945-9d39-9e70e54d0d45</Id>
  <Version>1.0.0</Version>
  <ProviderName>ExampleCompany</ProviderName>
  <DefaultLocale>en-us</DefaultLocale>
  <DisplayName DefaultValue="External Recipients Warning" />
  <Description DefaultValue="Warning when emails are sent to External Recipients" />
  <IconUrl DefaultValue="https://localhost:3000/assets/outline.png" />
  <HighResolutionIconUrl DefaultValue="https://localhost:3000/assets/color.png" />
  <SupportUrl DefaultValue="https://www.contoso.com/help"/>
  <AppDomains>
    <AppDomain>https://www.contoso.com</AppDomain>
	  <AppDomain>https://localhost:3000</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/commands.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>true</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.12">
          <bt:Set Name="Mailbox" />
        </bt:Sets>
      </Requirements>
      <Hosts>
        <Host xsi:type="MailHost">
          <Runtimes>
            <Runtime resid="WebViewRuntime.Url" >
               <Override type="javascript" resid="JSRuntime.Url"/>
            </Runtime>
          </Runtimes>
          <DesktopFormFactor>
            <FunctionFile resid="Commands.Url" />
            <ExtensionPoint xsi:type="LaunchEvent">
              <LaunchEvents>
                <LaunchEvent Type="OnMessageSend" FunctionName="onMessageSendHandler" SendMode="PromptUser" />
              </LaunchEvents>
              <SourceLocation resid="WebViewRuntime.Url" />
            </ExtensionPoint>
          </DesktopFormFactor>
        </Host>
      </Hosts>
      <Resources>
        <bt:Urls>
          <bt:Url id="Commands.Url" DefaultValue="https://localhost:3000/commands.html" />
          <bt:Url id="WebViewRuntime.Url" DefaultValue="https://localhost:3000/commands.html" />
          <bt:Url id="JSRuntime.Url" DefaultValue="https://localhost:3000/public/launchevent.js" />
        </bt:Urls>
      </Resources>
    </VersionOverrides>  
  </VersionOverrides>
</OfficeApp>

Here is my launchevent.js

console.log("launchevent.js loaded");

const customerDomain = "@example.com";

function onMessageSendHandler(event) {
    console.log("onMessageSendHandler triggered");
    let externalRecipients = [];
    Office.context.mailbox.item.to.getAsync((asyncResult) => {
        if (asyncResult.status === Office.AsyncResultStatus.Succeeded) {
            var recipients = asyncResult.value;
            recipients.forEach((recipient) => {
                if (!recipient.emailAddress.includes(customerDomain)) {
                    externalRecipients.push(recipient.emailAddress);
                }

                if (externalRecipients.length > 0) {
                    event.completed({
                        allowEvent: false,
                        errorMessage:
                            "The mail includes some external recipients, are you sure you want to send it?\n\n" +
                            externalRecipients.join("\n") +
                            "\n\nClick Send to send the mail anyway.",
                    });
                } else {
                    event.completed({ allowEvent: true });
                }
            });
        } else {
            event.completed({ allowEvent: true });
        }
    });
}

Office.onReady(() => {
    console.log("Office.js is ready");
    Office.actions.associate("onMessageSendHandler", onMessageSendHandler);
});

And finally here is my current webpack.config.js:

const fs = require('fs');
const path = require("path");
const HtmlWebpackPlugin = require("html-webpack-plugin");
const CopyWebpackPlugin = require("copy-webpack-plugin");

module.exports = {
  entry: {
        'launchevent-webview': "./src/launchevent/launchevent.js"
  },
  output: {
    path: path.resolve(__dirname, "dist"),
    filename: "[name].js",
    clean: true,
  },
  mode: "development", 
  module: {
    rules: [
    ],
  },
  plugins: [
    new CopyWebpackPlugin({
      patterns: [
            { from: "./src/launchevent/launchevent.js", to: "launchevent-webview.js" }
      ],
    }),
    new HtmlWebpackPlugin({
      template: "./src/commands/commands.html",
      filename: "commands.html",
    }),
  ],
  devServer: {
    static: {
      directory: path.join(__dirname, 'dist'),
      publicPath: "/public"
    },
    headers: {
      "Access-Control-Allow-Origin": "*",
    },
    server: {
      type: 'https',
      options: {
        key: fs.readFileSync(path.resolve(__dirname, 'node_modules/office-addin-dev-certs/localhost.key')),
        cert: fs.readFileSync(path.resolve(__dirname, 'node_modules/office-addin-dev-certs/localhost.crt')),
      },
    },
    port: process.env.npm_package_config_dev_server_port || 3000,
    client: false,
    hot: false,
  },
  resolve: {
    extensions: [".js", ".jsx", ".json"],
  },
};

Logs

I have ran this on the Classic Outlook and managed to get these error logs from event viewer:

Failed to parse element: VersionOverrides
Id=7a774f0c-7a6f-11e0-85ad-07fb4824019b, DisplayName=Bing Maps, Provider=Microsoft, StoreType=Unknown, StoreId=(null)
P1: Apps for Office
P2: 16.0.18129.20158
P3: 0x8004323E
P4: New Document

Failed to parse element: VersionOverrides
Id=bc13b9d0-5ba2-446a-956b-c583bdc94d5e, DisplayName=Suggested Meetings, Provider=Microsoft, StoreType=Unknown, StoreId=(null)
P1: Apps for Office
P2: 16.0.18129.20158
P3: 0x8004323E
P4: New Document

My Environment

  • Platform: Classic Outlook
  • Office version number: Microsoft® Outlook® for Microsoft 365 MSO (Version 2410 Build 16.0.18129.20158) 64-bit
  • Operating System: Windows 11
@microsoft-github-policy-service microsoft-github-policy-service bot added the Needs: triage 🔍 New issue, needs PM on rotation to triage ASAP label Dec 7, 2024
@exextoc exextoc added Needs: attention 👋 Waiting on Microsoft to provide feedback Area: Outlook Issue related to Outlook add-ins and removed Needs: triage 🔍 New issue, needs PM on rotation to triage ASAP labels Dec 7, 2024
@exextoc exextoc self-assigned this Dec 7, 2024
@VivianDZ
Copy link

Hi- we have the exact same issue with our add-in.

On Outlook Classic, our JS function doesn't even get called. Outlook behaves as if our Add-in is not available and shows the soft block, user prompt and allows the user to send the email anyway.

This worked untill the first of December. But hasn't worked since then.
The feature works fine in the Web and in the New Outlook.

Any information on a fix or workaround for this?

@aberamdatazoic
Copy link

I am also facing this same issue. It was working two weeks ago but its not working now. Can you provide any update if you have any? Its urgent!!

@timwan10
Copy link

Office.onReady(() => {
    console.log("Office.js is ready");
    Office.actions.associate("onMessageSendHandler", onMessageSendHandler);
});
Office.actions.associate("onMessageSendHandler", onMessageSendHandler);

The Office.actions.associate function must be run outside of Office.onReady. I made that change in your file and everything seemed to work:

image

Without that line Outlook can't find the function to call.

@VivianDZ / @aberamdatazoic Please open separate issues to track your issues, as the cause is likely different than this issue.

If you can provide the smallest add-in here that repros your problem, that can help a lot. (for example in this case the entire manifest and bundle.js was provided).

Most likely when something like this happens it's either because:

  • Outlook can't find your function (as was the case in this example)
  • There is something preventing your add-in from calling event.completed()
  • There is something incompatible in your bundle.js

In the second case, if your add-in runs you should be able to debug it and figure out what the issue is. If the Add-in Never Starts, you'll have to figure out what is incompatible in the bundle. If it used to work, it could be something that changed recently that is causing the incompatibility. If it never worked, remember that Win32 Classic uses a JS Runtime to run, and NOT a webview, so often things that rely on the DOM, or other webview elements can cause a problem.

Debugging your add-in information can be found here: https://learn.microsoft.com/en-us/office/dev/add-ins/outlook/debug-autolaunch?tabs=windows

Note that the dev team is aware that the process of figuring out what may be wrong in the JS Runtime bundle is tricky, and are working to improve that process, but I understand that does little to help you right now :(

@VivianDZ
Copy link

Thank you @timwan10 I will file a separate issue with the sample required which doesn't work on Classic Outlook.

@Buxt-Codes
Copy link
Author

Thank you @timwan10, the solution worked for me!

@timwan10 timwan10 closed this as completed Jan 9, 2025
@timwan10 timwan10 removed the Needs: attention 👋 Waiting on Microsoft to provide feedback label Jan 17, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Area: Outlook Issue related to Outlook add-ins
Projects
None yet
Development

No branches or pull requests

6 participants
@timwan10 @exextoc @VivianDZ @Buxt-Codes @aberamdatazoic and others