通过Outlook Web加载项从OWA获取附件内容 [英] Obtain attachment content from OWA through Outlook web add-in

查看:119
本文介绍了通过Outlook Web加载项从OWA获取附件内容的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试使用加载项中的Office.context.mailbox.item.getAttachmentsAsync()API调用从邮件项目中获取附件的内容,但是我遇到了一些意外的结果.

在我的加载项中,我获得了邮件项目中所有附件的列表:

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);
     }

这很好用...但是,我意识到附件ID的长度超过100个字符(实际上为180个字符).在getAttachmentContentAsync()函数的API参考中,第一个参数是附件ID,该参考指出:您要获取的附件的标识符.字符串的最大长度为100个字符."

因此,基于此,我认为我已经确定了问题所在.现在的问题是如何解决.该API需要什么附件ID?

谢谢!

更新:这是我用来检索附件内容的代码:

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);
            }
        });

我得到的错误是这样的: 无法获取未定义或空引用的属性状态"

出于故障排除的目的,我打印了附件ID: AAMkADU4OTU2Mjg4LThiNzktNDY0Yi1hZmE4LWFmMjAzZjczYjIxOQBGAAAAAADiRE + 1naePQ7MPCJEcJqgqBwCgpNXsitDwTY/mc0w2Y/zOAAAAAAEMAYGTYKYYPYYPYKYQAYQAYAYAQAYAQAYY

我从几页中了解到,不同的API期望附件ID的格式略有不同.所以我不确定这是否是问题的根源...

解决方案

尚未为OWA实现getAttachmentContent API.对于空结果对象-这是一个已知问题.它已被放入我们的积压中.很遗憾,我们目前没有时间表.

另外,为了回答第二个问题,由于您正在测试OWA,因此您可以简单地转到开发人员工具并在其中放置一个断点来测试外接程序,并使用控制台窗口检查其中的变量数据.

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...

解决方案

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.

这篇关于通过Outlook Web加载项从OWA获取附件内容的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆