0
votes

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, please follow “Get MIME content of an Outlook message attached to an Outlook item or group post” in docs.microsoft.com/en-us/graph/outlook-get-mime-message To get item attachment via REST, follow “Get MIME content of an Outlook message attached to an Outlook item or group post” in docs.microsoft.com/en-us/graph/outlook-get-mime-message - Outlook Add-ins Team - MSFT
ah right, went through this documentation and yeah it does not say anything about delegate access. docs.microsoft.com/en-us/exchange/client-developer/…. Might have to update the add-in to use both v2 API and Graph API. - Amyth
Did this solve your issue? We have posted the same comment as an answer to the question. - Outlook Add-ins Team - MSFT
Yes this has, we now just filter any itemAttachments for a shared mailbox. Thanks, would have been nice to see a reference in docs for this as I spent few days trying to work this out. Cheers - Amyth
Saying that, on testing found that some ‘.msg’ files were downloaded over REST as their type was ‘fileAttachment’ stackoverflow.com/q/62550158/1381217 but that’s fine as king as we can retrieve contents. Just a bit confusing to filter few ‘.msg’ files and not others. - Amyth

1 Answers

1
votes

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