Last active
May 20, 2018 00:44
-
-
Save gautamsi/1c267504b5d4c759afc2a93def67e4d1 to your computer and use it in GitHub Desktop.
Streaming Connection
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
"use strict"; | |
var ews = require("ews-javascript-api"); | |
var credentials = require("../credentials"); | |
ews.EwsLogging.DebugLogEnabled = false; | |
var exch = new ews.ExchangeService(ews.ExchangeVersion.Exchange2013); | |
exch.Credentials = new ews.ExchangeCredentials(credentials.userName, credentials.password); | |
exch.Url = new ews.Uri("https://outlook.office365.com/Ews/Exchange.asmx"); | |
exch.SubscribeToStreamingNotifications([new ews.FolderId(ews.WellKnownFolderName.Inbox)], ews.EventType.NewMail, ews.EventType.Created, ews.EventType.Deleted, ews.EventType.Modified, ews.EventType.Moved, ews.EventType.Copied, ews.EventType.FreeBusyChanged) | |
.then(function (streamingSubscription) { | |
var connection = new ews.StreamingSubscriptionConnection(exch, 1); | |
console.log("subscribing....: "); | |
connection.AddSubscription(streamingSubscription); | |
connection.OnNotificationEvent.push(function (obj, notificationArgs) { | |
console.log("notification received: "); | |
ews.EwsLogging.Log(obj, true, true); | |
// EwsLogging.Log(notificationArgs, true, true); | |
}); | |
connection.OnDisconnect.push(function (connection, subscriptionErrorEventArgsInstance) { | |
console.log("disconnecting..."); | |
ews.EwsLogging.Log(subscriptionErrorEventArgsInstance, true, true); | |
//access subscriptionErrorEventArgsInstance | |
//connection.Open(); | |
}); | |
connection.Open(); | |
}, function (err) { | |
console.log("ERROR: --------------- "); | |
console.log(err); | |
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import { | |
EwsLogging, | |
ExchangeService, | |
ExchangeVersion, | |
ExchangeCredentials, | |
Uri, | |
FolderId, | |
EventType, | |
WellKnownFolderName, | |
StreamingSubscriptionConnection, | |
} from "ews-javascript-api"; | |
import credentials = require("../credentials"); | |
EwsLogging.DebugLogEnabled = false; | |
var exch = new ExchangeService(ExchangeVersion.Exchange2013); | |
exch.Credentials = new ExchangeCredentials(credentials.userName, credentials.password); | |
exch.Url = new Uri("https://outlook.office365.com/Ews/Exchange.asmx"); | |
exch.SubscribeToStreamingNotifications( | |
[new FolderId(WellKnownFolderName.Inbox)], | |
EventType.NewMail, | |
EventType.Created, | |
EventType.Deleted, | |
EventType.Modified, | |
EventType.Moved, | |
EventType.Copied, | |
EventType.FreeBusyChanged) | |
.then((streamingSubscription) => { | |
let connection = new StreamingSubscriptionConnection(exch, 1); | |
console.log("subscribing....: "); | |
connection.AddSubscription(streamingSubscription); | |
connection.OnNotificationEvent.push((obj, notificationArgs) => { | |
console.log("notification received: ") | |
EwsLogging.Log(obj, true, true); | |
// EwsLogging.Log(notificationArgs, true, true); | |
}); | |
connection.OnDisconnect.push((connection, subscriptionErrorEventArgsInstance) => { | |
console.log("disconnecting..."); | |
EwsLogging.Log(subscriptionErrorEventArgsInstance, true, true); | |
//access subscriptionErrorEventArgsInstance | |
//connection.Open(); | |
}); | |
connection.Open(); | |
}, (err) => { | |
console.log("ERROR: --------------- "); | |
console.log(err); | |
}); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
I am using the javascript version in Node.js. It connects to the Exchange server and runs through the set-up code without an errors. The issue is that it never receives Inbox notifications. When the connection time expires the onDisconnect is called and it disconnects without errors.
I cannot figure out why it never receives NotificationEvents. Is there a configuration on the Exchange server that needs to be set in order for the server to send notifications?