0
votes

I am working on a project where we are attempting to attach a variety of documents to a draft email via an outlook add-in created in React/TypeScript. Basically, we have the following code snippet that we're using to add files as attachments to the current email draft:

     public attachFile(fileUrl: string, filename: string): Promise<Office.AsyncResult<any>> {
        return new Promise(async (resolve, reject) => {
            (Office.context.mailbox.item as any).addFileAttachmentAsync(
                fileUrl,
                filename,
                { asyncContext: null },
                (attachResult: Office.AsyncResult<any>) => {
                    resolve(attachResult);
                }
            );
        });
    }

Now typically, when this function is fired it looks something like this:

const outlookApp = this.officeApp as OutlookOfficeApp;
const attachResult = await outlookApp.attachFile(attachUrl, fileName);

In an example where this works, the file name would be Document 1.docx - but this function consistently fails for .msg files.

When attempting to attach a .msg file, from the attachResult it would appear that the attachment did not fail since this is the result we get back: AttachResult Object

But, when we inspect if the attachment failed by using the following function (with the value property that is returned on the attachResult object:

     public async didAttachFail(attachmentOutlookId: string): Promise<boolean> {
        const attachments = await new Promise(async results => {
            const mailboxItem = Office.context.mailbox.item;
            const options = { asyncContext: { currentItem: mailboxItem } };
            Office.context.mailbox.item.getAttachmentsAsync(
                options,
                (response: Office.AsyncResult<Office.AttachmentDetails[]>) => {
                    results(response);
                }
            );
        });
        // Atachments will have 0 size if they failed to download
        return (attachments as Office.AsyncResult<Office.AttachmentDetails[]>).value.some(
            x => x.id === attachmentOutlookId && x.size === 0
        );
    }

It would appear that the size of the item is 0 - which in turn means it did not attach correctly. When downloading the file from the fileUrl specified for addFileAttachmentAsync (which I've done to confirm that the URL supplied works), I can clearly see that the item is not 0KB;

Message File Size

Is there anything we're doing wrong when it comes to the attachment of .msg files, or is there another way of doing this? The outlined code works for a variety of other content types, including Word documents, images, PowerPoint, and Excel files. It only fails for Outlook messages/.msg files.

**Edit 1: I'm using the Outlook app on my desktop (Version 2005, Build 12827.20268), my Windows version is 1909 (Build 18363.900). I've also tested this in Outlook Online, in Chrome (Version 83.0.4103.97) and Microsoft Edge (Version 83.0.478.45) with the same results.

**Edit 2:

  • I am able to manually add this .msg file manually.
  • Additionally, there are no errors when attaching the debugger (and that makes sense, the attachment's size is 0 when looking at the output of using addFileAttachmentAsync).
  • So the last call was to test everything using Script Lab (thanks for the reminder on this one) and;

Here are the .yaml for the script I created: https://gist.github.com/svbygoibear/9febca6eeaca5748d15995dd879cae64#file-add-attachments-outlook-outlook-yaml

Now here I've made a whole bunch of sample documents (one image, one .docx and one .msg file) to test addFileAttachmentAsync. All the files (including the .msg file) attaches correctly, but if you see the output from the last method (which is the getAttachmentsAsync) you will see that the .msg files' size is 0:

enter image description here

We use this to check if files have been correctly attached - so it seems that the issue is with getAttachmentsAsync. Is it expected to return a 0 size for .msg files?

1
What Outlook platform are you facing this issue on? - Outlook Add-ins Team - MSFT
Ah let me add all the version numbers in the original question - but I'm using the Outlook app on my desktop (Version 2005, Build 12827.20268), my Windows version is 1909 (Build 18363.900). I've also tested this in Outlook Online, in Chrome (Version 83.0.4103.97) and Microsoft Edge (Version 83.0.478.45) with the same results. - svbyogibear
We are unable to repro this issue. Are you able to attach this file manually? - Outlook Add-ins Team - MSFT
Can you repro this in ScriptLab? Scriplab is an add-in for Outlook, which is available in the store. Instructions for installing add-ins from the store can be found here. In this add-in, there are sample snippets, such as "Manipulate attachments (Item Compose)" , that can be used to try to repro this issue. - Outlook Add-ins Team - MSFT
You can also try attaching a debugger to see any issues with the add-in. - Outlook Add-ins Team - MSFT

1 Answers

0
votes

Thanks for reporting this issue. After careful consideration, our team has decided to not fix this issue in the short term. We recommend you to upvote or create a new Uservoice item, this will give us visibility of the commonality of it and will help with our prioritization. If we end up working on this issue we will re-activate as needed.