disem
disem

Reputation: 37

Outlook Add-In compose mode: modify + send scenario

Problem we're solving

For many months we used makeEwsRequestAsync to update & send drafts right from the Add-In context. This approach is facing Outlook's cache mode limitations and forces us to retry EWS requests for unknown period of time before we can finish the process. Considering real customers complains about processing time we have changed the flow and moved drafts processing to the backend.

Here's a schematic diagram of what're we trying to do - draft message processing flow

What went wrong?

After shipping this change to production we faced 2 major issues that we're trying to investigate and resolve now. Here's some context:

Issues

1. Draft is not found in the API

There are number of drafts that never gets persisted on the backend: failed draft searches over retries. Increased number of NotFounds starting at 6 retry shows us that processing job was able to get an email for a while but it was sent by a customer manually.

2. Draft has no sync_id in the body

We have tried using EWS on the backend a year ago to process emails on the backend, we had to revert as some of emails that we sent didn't match customer's expectations: random parts of email body were missing. Assuming that API synchronisation can take some time, we started inserting empty link to the email body using office-js's body.prependAsync. It looks like this: <a href="#sync-${syncId}">&zwnj;</a>. By doing that we were able to verify that draft that we received through the API is synced to the point where user pressed command button. Unfortunately our 45 minutes for retries seems to be not enough to sync. failed sync_id check attempts

Things we want to understand and get some help with:

  1. Is there a better way to know that email is in correct state on the backend?
  2. Is it true that Microsoft Graph API and Outlook REST API are getting synchronised simultaneously? In other words - is there any value in using both APIs?
  3. Is there Windows Outlook Desktop settings that can help in faster sync of drafts? (except of turning off the cache mode)
  4. What is the expected worst case time to wait before we can get the draft on the backend?
  5. Any other comments/thoughts on this

Upvotes: 1

Views: 820

Answers (1)

user16457328
user16457328

Reputation:

How about skipping the drafts-collection step and getting the client to POST your back-end with a copy of the email themselves?

function sendit() {
  Office.context.mailbox.getCallbackTokenAsync({ isRest: true }, function(result) {
    var ewsId = Office.context.mailbox.item.itemId;
    var token = result.value;
    var restId = Office.context.mailbox.convertToRestId(ewsId, Office.MailboxEnums.RestVersion.v2_0);
    var getMessageUrl = Office.context.mailbox.restUrl + "/v2.0/me/messages/" + restId;

    var xhr = new XMLHttpRequest();
    xhr.open("GET", getMessageUrl);
    xhr.setRequestHeader("Authorization", "Bearer " + token);
    xhr.onload = function(e) {
      // Send this to your server:-
      console.log(this.response); // <-- this is the complete email (excluding attachments though)
    };
    xhr.send();
  });
}

Upvotes: 0

Related Questions