Amyth
Amyth

Reputation: 1517

Outlook add-in : Get shared mailbox ItemAttachment using EWS

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://learn.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.

Upvotes: 0

Views: 546

Answers (1)

user7823505
user7823505

Reputation:

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://learn.microsoft.com/en-us/graph/outlook-get-mime-message

Upvotes: 2

Related Questions