outlookoutlook-web-addins

Outlook JS web add-in: can't get to, cc or bcc field from mail item in classic desktop Outlook composer if activated by mailto link


I'm writing an Outlook JS web add-in. It has an event-based activation on the onNewMessageCompose event.

In my onNewMessageComposeHandler function, I am trying to retrieve the to, cc and bcc fields of the mail item:

function onNewMessageComposeHandler(event) {
  Office.context.mailbox.item.to.getAsync(result => console.log(JSON.stringify(result)));
}

When the composer is activated by a mailto link such as mailto:email@example.com, the code logs the to field normally in the web based "new" Outlook for Windows:

{
    "value": [{
        "emailAddress": "email@example.com",
        "displayName": "email@example.com",
        "recipientType": "other"
    }],
    "status": "succeeded"
}

but if I change the default app to handle mailto to the classic desktop Outlook app, the code always logs an empty array:

{
    "value": [],
    "status": "succeeded"
}

The same thing happens to cc and bcc fields when the composer is triggered by mailto:email1@example.com?cc=email2@example.com&bcc=email3@example.com.

I've even tried putting in a 2 second wait just to test things out but the outcome is exactly the same:

function onNewMessageComposeHandler(event) {
  setTimer(
    () => Office.context.mailbox.item.to.getAsync(result => console.log(JSON.stringify(result))),
    2000);
}

Does anyone know if I'm doing something wrong here?


Solution

  • I know this is not great but currently "as designed". The problem is that classic outlook does not resolve these recipients quickly enough for this API to work during the on new message compose event. It's a race condition between these two operations on this client. I expect this would work if you try a longer delay - does it?