Skip to content

Instantly share code, notes, and snippets.

@gautamsi
Last active May 20, 2018 00:44
Show Gist options
  • Save gautamsi/1c267504b5d4c759afc2a93def67e4d1 to your computer and use it in GitHub Desktop.
Save gautamsi/1c267504b5d4c759afc2a93def67e4d1 to your computer and use it in GitHub Desktop.
Streaming Connection
"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);
});
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);
});
@MichaelWhite63
Copy link

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?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment