The setup is Outlook 2013 and Exchange Server 2013 (on-premise). According to Get attachments of an Outlook item from the server:
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.
Since the setup is on-premise, it isn't exposed to the outside world. So, the remote service will not be able to access it.
Can something like this be done purely in JavaScript?
I tried this without success:
function getAttachmentViaSOAP(attachmentId) {
var request =
'<?xml version="1.0" encoding="utf-8"?>' +
'<soap:Envelope xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"' +
' xmlns:xsd="http://www.w3.org/2001/XMLSchema"' +
' xmlns:soap="http://schemas.xmlsoap.org/soap/envelope/"' +
' xmlns:t="http://schemas.microsoft.com/exchange/services/2006/types">' +
' <soap:Header>' +
' <RequestServerVersion Version="Exchange2013" xmlns="http://schemas.microsoft.com/exchange/services/2006/types" soap:mustUnderstand="0" />' +
' </soap:Header>' +
' <soap:Body>' +
' <GetAttachment xmlns="http://schemas.microsoft.com/exchange/services/2006/messages" xmlns:t="http://schemas.microsoft.com/exchange/services/2006/types">' +
' <AttachmentShape/>' +
' <AttachmentIds>' +
' <t:AttachmentId Id="' + attachmentId + '"/>' +
' </AttachmentIds>' +
' </GetAttachment>' +
' </soap:Body>' +
'</soap:Envelope>';
return request;
}
function sendAttachmentRequest(attachment) {
var settings = {
'async': true,
'crossDomain': true,
'url': attachment.outlook_exchange_server_url,
'method': 'POST',
'headers': {
'Authorization': 'Bearer ' + attachment.attachment_token,
'Content-Type': 'text/xml; charset=utf-8',
'Cache-Control': 'no-cache'
},
'data': getAttachmentViaSOAP(attachment.attachment_id)
}
$.ajax(settings).done(function (response) {
console.log(response);
});
}
Can CORS settings be added to the IIS/Exchange server to allow this? or any other way of doing it?