Outlook add-in : Get shared mailbox ItemAttachment using EWS

丶灬走出姿态 提交于 2020-06-27 04:09:09

问题


Our outlook add-in works in most scenarios on a shared Mailbox, except when the attachment in an email is of type "Office.MailboxEnums.AttachmentType.Item" e.g ".msg" file.

Environment is Outlook web and desktop.

We mostly get all attachment content via REST, as they are returned as base-64, but with "AttachmentType.Item" the body is email body and not a base-64. In this case, we make a call to EWS to download that attachment, process the body and return as byte[];

The problem we are currently having is that, when the attachment is of type ".msg" on a shared mailbox, EWS return with the error "ErrorAccessDenied", This is strange as, other attachments are downloaded and we've made sure that we pass "TargetMailbox"

We get the targetMailbox by: https://docs.microsoft.com/en-us/office/dev/add-ins/outlook/delegate-access

Once we have the accessToken and targetMailbox we call the backend

GetData(token, Id){
    let sharedMailBox = GetTargetMailbox(token);
    return this.$http.post("DownloadAttachment", {
        token: sharedMailBox.token,
        url: Office.context.mailbox.ewsUrl,
        attachmentId: Id,
        mailbox: sharedMailBox.mailbox
    }, {
        responseType: 'arraybuffer',
    }).then(response => response.data);
}

backend

 DownloadAttachment(Request request){
            var service = new ExchangeService
            {
                Credentials = request.token,
                Url = request.url
            };
            
            if (request.mailbox != "")
            {
                FolderId SharedMailbox = new FolderId(WellKnownFolderName.Inbox, request.TargetMailbox);
                ItemView itemView = new ItemView(1);
                service.FindItems(SharedMailbox, itemView); //This throws ErrorAccessDenied
            }
        
            //do other stuff and return data
        
}

Not sure, what to do to get the itemAttachment for Shared mailbox.


回答1:


EWS is not supported in a shared mailbox, only REST. This might have been missed out in our documentation. We'll update it. To get item attachment via REST, follow “Get MIME content of an Outlook message attached to an Outlook item or group post” in https://docs.microsoft.com/en-us/graph/outlook-get-mime-message



来源:https://stackoverflow.com/questions/62507176/outlook-add-in-get-shared-mailbox-itemattachment-using-ews

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