Skip to content

Instantly share code, notes, and snippets.

@maccyber
Created May 9, 2016 11:53
Show Gist options
  • Save maccyber/a57e3b7f8ded3d72205c817cf4c5b377 to your computer and use it in GitHub Desktop.
Save maccyber/a57e3b7f8ded3d72205c817cf4c5b377 to your computer and use it in GitHub Desktop.
var ews = require('ews-javascript-api')
var ntlmXHR = require('./ntlmXHRApi')
var config = require('../config')
var ntlmXHRApi = new ntlmXHR.NtlmXHRApi(config.username, config.password)
// create ExchangeService object
function getTasks (callback) {
var exch = new ews.ExchangeService(ews.ExchangeVersion.Exchange2013)
exch.XHRApi = ntlmXHRApi
exch.Credentials = new ews.ExchangeCredentials(config.username, config.password)
// ews.EwsLogging.DebugLogEnabled = false // turn off logging
exch.ImpersonatedUserId = new ews.ImpersonatedUserId(ews.ConnectingIdType.SmtpAddress, 'usersmail@mail.com')
// set ews endpoint url to use
exch.Url = new ews.Uri(config.url) // you can also use exch.AutodiscoverUrl
var folder = new ews.FolderId(ews.WellKnownFolderName.Tasks)
var sf = new ews.SearchFilter.IsNotEqualTo(ews.TaskSchema.IsComplete, true)
var view = new ews.ItemView(config.tasks)
var items = []
var i = 0
exch.FindItems(folder, sf, view)
.then((response) => {
items = response.Items
var obj = []
for (i in items) {
var item = {
systemid: 'exchange',
timestamp: new Date().getTime(),
title: items[i].Subject,
url: config.tasksUrl
}
obj.push(item)
}
return callback(null, obj)
}, (err) => {
return callback(err)
}
)
}
module.exports = getTasks
getTasks(function (err, data) {
console.log(err || data)
})
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment