0
votes

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?

2

2 Answers

0
votes

An Outlook Web Add-in is, at its core, a web application running on a remote web host. If your web server is unable to communicate with your Exchange Server then almost nothing would work.

Given such a severe constraint, Outlook Web Add-ins are likely not suitable for your solution.

0
votes

This cannot be done today through JavaScript. However, we are considering how we could solve this in more recent clients of Outlook. This means if a solution is added it would not be supported on an Outlook 2013 and Exchange 2013 on-prem setup.