Berend Engelbrecht's avatar
Berend Engelbrecht
Brass Contributor
Apr 10, 2025
Status:
New

Implement Office.context.mailbox.item.getAsFileAsync for draft messages

We have a requirement in an Office.js add-in to do the following:

  • Automatically send a message
  • Save the sent message

The functionality was previously implemented using EWS and Office.context.mailbox.getCallbackTokenAsync. However, both are being phased out. Office.auth.getAccessToken is supposed to replace Office.context.mailbox.getCallbackTokenAsync, but we did not manage to get it to work in my add-in. To send the mail, Office.context.mailbox.item.sendAsync is now available, but it currently does not allow to execute code after sending. So we want to collect the draft before sending and process it in the back-end of our web app.

We are hindered here by the fact that Office.context.mailbox.item.getAsFileAsync cannot be used on a draft. The function is currently not available for a draft message, we get the error message `Office.context.mailbox.item.getAsFileAsync is not a function` when trying to use it. The same works fine for messages in other Outlook folders like Inbox or Sent Items.

To assemble eml-like text for the draft message so that we can save it in the back end of our add-in requires quite a lot of code. Also, img nodes reference external content, e.g., they have a src like `src="https://attachments.office.net/owa/.../service.svc/s/GetAttachmentThumbnail?id=` with id being a base64 string, where an eml should have `src="cid:` with cid referencing to a short id of a mime part in the same eml. There is no straightforward way to resolve all images when building an eml client-side.

3 Comments

  • I feel myself that API design could be more careful. It is peculiar and unexpected to a developer that function X operating on an email message can be used in the MessageReadCommandSurface but not in the MessageComposeCommandSurface. In Outlook you can save both a draft and a sent or received message in MIME format. I tried classic desktop and outlook.office.com web version.

  • ashishtank's avatar
    ashishtank
    Copper Contributor

    Indeed, this would be really helpful for lot many scenarios.