问题
I know I can access to the attachments via Office.context.mailbox.item.attachments
Also for each of the attachment I get to access to its members like name
But can I actually access to its content and send it to a external server to show it? For example I want to send a pdf attachment to a server, and on the server I want to show the content of that pdf file.
回答1:
Turns out that An Outlook Add-in cannot pass the attachments of a selected item directly to the remote service that runs on your server. Instead, the add-in can use the attachments API to send information about the attachments to the remote service. The service can then contact the Exchange server directly to retrieve the attachments.
function getAttachmentToken() {
if (serviceRequest.attachmentToken == "") {
Office.context.mailbox.getCallbackTokenAsync(attachmentTokenCallback);
}
}
function attachmentTokenCallback(asyncResult, userContext) {
if (asyncResult.status === "succeeded") {
// Cache the result from the server.
serviceRequest.attachmentToken = asyncResult.value;
serviceRequest.state = 3;
testAttachments();
} else {
showToast("Error", "Could not get callback token: " + asyncResult.error.message);
}
}
// Initialize a context object for the add-in.
// Set the fields that are used on the request
// object to default values.
var serviceRequest = {
attachmentToken: '',
ewsUrl : Office.context.mailbox.ewsUrl,
attachments : []
};
Retrieve attachment via EWS managed API
来源:https://stackoverflow.com/questions/51762073/access-to-the-attachment-in-outlook-web-add-in