nmarus / node-ews

A simple JSON wrapper for the Exchange Web Services (EWS) SOAP API.
MIT License
116 stars 52 forks source link

How can I use impersonation and access other mailboxes #39

Closed rbartholomay closed 7 years ago

rbartholomay commented 7 years ago

Hi,

can you provide a sample how to use impersonation? And perhaps another example to open a shared mailbox?

patrickpxp commented 7 years ago

here's an example of impersonation for getting Out of Office settings for another user (tested on Office365)

var EWS = require('node-ews');

// exchange server connection info
var ewsConfig = {
  username: the.admin@example.com,
  password: the.adminpassword1234$,
  host: 'https://outlook.office365.com',
  auth: 'basic'
};

// initialize node-ews
var ews = new EWS(ewsConfig);

// define ews api function
var ewsFunction = 'GetUserOofSettings';

// define ews api function args
var ewsArgs = {
  'Mailbox': {
    'Address':'john.doe@example.com'
  }
};

// define custom soap header
var ewsSoapHeader = {
  't:ExchangeImpersonation': {
    't:ConnectingSID': {
      't:SmtpAddress': 'john.doe@example.com'
    }
  }
};

// query EWS and print resulting JSON to console
//ews.run(ewsFunction, ewsArgs)
ews.run(ewsFunction, ewsArgs, ewsSoapHeader)
  .then(result => {
    console.log(JSON.stringify(result));
  })
  .catch(err => {
    console.log(err.message);
  });
rbartholomay commented 7 years ago

Thanks! - This is a really nice library!

nmarus commented 7 years ago

Closing due to inactivity.