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.