Search code examples
office-jsoutlook-web-addins

Attaching files from external systems which require authentication when using Office.context.mailbox.displayNewMessageForm


I am creating a new mail dialog using the Office.context.mailbox.displayNewMessageForm and passing an attachment URL. It appears that the Office server goes to retrieve the file vs the client, so what I actually get back is the login screen for my server. The client is already authenticated with the external system, and can open the file with no login prompts.

To get around this, I thought I'd build a proxy, where I send the clientid, clienttoken etc and verify the authentication on my backend system and then retrieve the attachment and pass it back to the requesting machine. This would work fine, except there seems to be a limit on the size of URI that can be passed to the attachment parameter, as I get the error:

Sys.ArgumentOutOfRangeException: One or more of the attachment URLs is too long.

How do you attach attachments form URLs that are not in the all contained Microsoft universe?

I saw in another thread there was discussion of attaching from base64, but I don't think that has ever shipped.

Many thanks


Solution

  • The attachment URL for Office.context.mailbox.displayNewMessageForm should be a URL that has no need for authentication. So, it can be a publicly accessible URL, or a URL that is generally accessible within a private network as long as the user is within that network. Also note that in OWA, the attachment must be able to be accessed by the Exchange backend in order to attach the file.

    In our JavaScript API library, we have a restriction of 2048 characters for URLs. This is because we have traditionally supported multiple browsers including Internet Explorer, which has a maximum path length of 2048 characters. More information here. Also, 2048 characters is a general web guideline to ensure that the URLs work on every client and server, so you will have to keep your URLs within that limit.

    If you want to attach a file using base64, we shipped the API Office.context.mailbox.item.addFileAttachmentFromBase64Async in Requirement Set 1.8 just over 2 years ago (September 2019). Please try it to see if this helps your scenario.