Bart Loos
Bart Loos

Reputation: 25

Outlook Add-in unable to add attachments to message

Trying to add an attachment to an email message from an outlook add-in is returning the following error:

status: failed
code:9007    
message:"The attachment cannot be added to the item."    
name:"AttachmentUploadGeneralFailure"

This happens using Outlook on the web in any browser. On the Outlook 2013/2016 desktop clients, the attachment is added successfully.

The file is hosted on the same domain where the add-in is running, using HTTPS and a valid certificate (not self-signed). Does not work when using HTTP instead of HTTPS either. I am able to download the file by entering the URL in the browser. No "GET" request is made to the server to download the attachment.

The issue seems to be specific to my web server. If I try to attach a random file from the internet, it works fine.

Update: the file is only accessible to the authenticated add-in user. It is not publicly accessible. That is probably why it doesn't work. Is there any way to work around this?

mailbox.item.addFileAttachmentAsync(
    attachmentUrl,
    fileName,
    function (result) {
        if (result.status === Office.AsyncResultStatus.Failed) {
            console.log(result.error.message);
        }
    });

Upvotes: 2

Views: 848

Answers (1)

Marc LaFleur
Marc LaFleur

Reputation: 33094

The problem is that your file requires authentication.

With Outlook on the desktop, the attachmentUrl is being sent to the Outlook client to download and attach. Since this is all happening within the same context, the authentication is just being passed along to your file server.

With OWA however, the attachmentUrl is sent to the Server to download. Since the Server isn't authenticated, the file isn't accessible and can't download and attach it to the message.

One potential workaround is to provide a temporary URI that is publicly accessible but that only lives for a a short time. This is how Microsoft Graph API handles downloading files from OneDrive. It generates a URI that can only be used once and self-destructs after a couple of minutes.

Another option is to use an intermediary such as Azure Blog Storage to host the files and leverage shared access signatures to secure access to the file. Depending on the number and size of your files, this can be an extremely inexpensive to avoid rolling your own solution (as in the penny per GB kind of inexpensive).

Upvotes: 1

Related Questions