Obtain attachment content from OWA through Outlook web add-in

微笑、不失礼 提交于 2020-02-29 01:50:49

问题


I'm trying to get the content of an attachment from a mail item using the Office.context.mailbox.item.getAttachmentsAsync() API call from my add-in, however I'm running into some unexpected results...

In my add-in, I get a list of all the attachments in the mail item:

var listOfAttachments = item.attachments;
if (listOfAttachments.length > 0) {
    for (i = 0; i < listOfAttachments.length; i++) {
        _att = listOfAttachments[i];
        console.log("Attachment name: " + _att.name);
        console.log("Attachment type: " + _att.attachmentType);
        console.log("Attachment content type: " + _att.contentType);
        console.log("Attachment ID: " + _att.id);
        console.log("string length: " + _att.id.length);
     }

This works fine... However, I realised that the attachment ID, is longer than 100 characters (180 characters actually). And in the API reference of the getAttachmentContentAsync() function, the first parameter is the attachment ID, which the reference states: "The identifier of the attachment you want to get. The maximum length of the string is 100 characters."

So based on that, I think I have identified the problem. The issue now is, how to solve it. What attachment ID is this API expecting?

Thanks!

Update: This is the code that I'm using to retrieve the attachment content:

var options = { asyncContext: { type: _att.attachmentType } };
item.getAttachmentContentAsync(_att.id, options, function (result) {
            if (result.status == Office.AsyncResultStatus.Succeeded) {
                console.log("Call returned success!");
                var AttachmentContent = result.value; // Get the attachment content
                if (AttachmentContent.format == Office.MailboxEnums.AttachmentContentFormat.Base64) {
                    // handle file attachment
                    console.log("Base64 String: " + AttachmentContent.content);
                }
                else if (result.format == Office.MailboxEnums.AttachmentContentFormat.Eml) {
                    // handle item attachment
                }
                else {
                    // handle cloud attachment  
                }
            } else {
                var err = result.error;
                console.log("Call failed: " + err.name + ": " + err.message);
            }
        });

The error that I'm getting is this: Unable to get property 'status' of undefined or null reference

For purpose of troubleshooting, I printed out the attachment id: AAMkADU4OTU2Mjg4LThiNzktNDY0Yi1hZmE4LWFmMjAzZjczYjIxOQBGAAAAAADiRE+1naePQ7MPCJEcJqgqBwCgpNXsitDwTY/mc0w2Y/zOAAAAAAEMAACgpNXsitDwTY/mc0w2Y/zOAAARXFqBAAABEgAQAN0M5JhRvPxIoP5KYNYRk54=

I read from a few pages that different API expects slightly different format of the attachment id. So I'm not sure if this is the source of the issue...


回答1:


The getAttachmentContent API is not yet implemented for OWA. For the null result object - This is a known issue. It has been put on our backlog. We unfortunately have no timelines to share at this point.

Also, to answer you second question, since you are testing OWA, you can simply go to developer tools and place a breakpoint there to test the add-ins and use the console window to check variables data in them.



来源:https://stackoverflow.com/questions/53800823/obtain-attachment-content-from-owa-through-outlook-web-add-in

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!